On 21/11/2021 17:01, Ihor Radchenko wrote:
Max Nikulin writes:

My draft version is attached. Ihor, thank you for inspiration. Feel free
to improve it. I hope, it makes problem more apparent to user who tries
to customize markers.

A patch is attached. I have dropped changes in documentation since I am not the author of them.

For init file (entries may be in arbitrary order)

(custom-set-variables
  '(org-emphasis-alist
     (quote
       (
        ("*" bold)
        ("_" underline)
        ("=" org-verbatim verbatim)
        ("/" italic)
        ("~" org-code verbatim)
        ("!" org-todo) ;; does not work
        ("+" (:strike-through t)))))
  )

emacs --eval "(customize-variable 'org-emphasis-alist)"

looks as the following

Hide Org Emphasis Alist:
[INS] [DEL] :
            Marker: [Value Menu] *Bold*
Font: [Value Menu] Face: (sample) bold


[ ] verbatim


[INS] [DEL] :
            Marker: [Value Menu] _Underline_
Font: [Value Menu] Face: (sample) underline


[ ] verbatim


[INS] [DEL] :
            Marker: [Value Menu] =Verbatim=
Font: [Value Menu] Face: (sample) org-verbatim


            [X] verbatim
[INS] [DEL] :
            Marker: [Value Menu] /Italic/
Font: [Value Menu] Face: (sample) italic


[ ] verbatim


[INS] [DEL] :
            Marker: [Value Menu] ~Code~
Font: [Value Menu] Face: (sample) org-code


            [X] verbatim
[INS] [DEL] :
Marker: [Value Menu] Unsupported ignored character: !


Font: [Value Menu] Face: (sample) org-todo


[ ] verbatim


[INS] [DEL] :
            Marker: [Value Menu] +Strike-through+
            Font: [Value Menu] Property list:
                        [INS] [DEL] :
Key: :strike-through


Value: t


            [INS]
[ ] verbatim


[INS]
   [ State ]: SAVED and set.
>From 1ee52f7ffc1039fd442775e9267403f1dca86b88 Mon Sep 17 00:00:00 2001
From: Max Nikulin <maniku...@gmail.com>
Date: Mon, 22 Nov 2021 23:56:15 +0700
Subject: [PATCH] org.el: Warning for unsupported markers in
 `org-set-emphasis-alist'

* lisp/org.el (org-emphasis-alist, org-set-emphasis-alist): Change
custom variable type definition and add :set parameter to warn users
that non-standard marker characters are ignored.

Attempts to introduce new markers have been discussed enough times to
add some code that should prevent wasting of time.

Unfortunately there is no way to issue warning for e.g. `setq'.
---
 lisp/org.el | 47 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 41 insertions(+), 6 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index df3d139c7..1a65b6db8 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3771,6 +3771,25 @@ newline      The maximum number of newlines allowed in an emphasis exp.
 
 You need to reload Org or to restart Emacs after setting this.")
 
+(defun org-set-emphasis-alist (var value)
+  "Set VAR (`org-emphasis-alist') to VALUE and check it for ignored characters.
+Warn user that Org syntax can not be extended with new emphasis markers
+if such attempt is detected.  The function is intended for :set argument
+of `defcustom'."
+  (set var value)
+  (let ((unsupported
+	 (delq nil
+	       (mapcar
+                (lambda (entry)
+                  (let ((marker (car entry)))
+                    (unless (member marker '("*" "/" "_" "=" "~" "+")) marker)))
+                value))))
+    (when unsupported
+      (message "Warning! Unsupported markup characters '%s' detected in `%s'"
+	       (mapconcat #'identity unsupported " ")
+	       (symbol-name var))))
+  value)
+
 (defcustom org-emphasis-alist
   '(("*" bold)
     ("/" italic)
@@ -3784,18 +3803,34 @@ for example *bold*, _underlined_ and /italic/.  This variable sets the
 marker characters and the face to be used by font-lock for highlighting
 in Org buffers.
 
+Do not change the characters and do not add new ones to use custom
+markers for existing styles or to introduce new styles.  Org syntax is
+not meant to be configurable and such modifications will not work with
+export.
+
 You need to reload Org or to restart Emacs after customizing this."
   :group 'org-appearance
   :set 'org-set-emph-re
   :version "24.4"
   :package-version '(Org . "8.0")
+  :set #'org-set-emphasis-alist
   :type '(repeat
-	  (list
-	   (string :tag "Marker character")
-	   (choice
-	    (face :tag "Font-lock-face")
-	    (plist :tag "Face property list"))
-	   (option (const verbatim)))))
+          (group
+           (choice
+            :tag "Marker"
+            (const :tag "*Bold*" "*")
+            (const :tag "/Italic/" "/")
+            (const :tag "_Underline_" "_")
+            (const :tag "+Strike-through+" "+")
+            (const :tag "=Verbatim=" "=")
+            (const :tag "~Code~" "~")
+            ;; To warn users that it does not work.
+            (string :tag "Unsupported ignored character"))
+           (choice
+            :tag "Font"
+            (face :tag "Face")
+            (plist :tag "Property list"))
+           (option (const verbatim)))))
 
 (defvar org-protecting-blocks '("src" "example" "export")
   "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
-- 
2.25.1

Reply via email to