On 16/11/2021 14:43, Ihor Radchenko wrote:
Max Nikulin writes:

Better docs and some restriction on defcustom values were discussed earlier:
https://list.orgmode.org/87k0oyd3pw....@nicolasgoaziou.fr/
Nicolas Goaziou. Re: Using backticks for the inline code delimeter? Mon,
19 Apr 2021 11:27:07 +0200

Sorry, I have not prepared a patch. I am not confident with defcustom
fine tuning and have not experimented with it since that time.

Maybe something like the attached?

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. Have I missed some undesired side effects?

Unfortunately with "set" type in defcustom "catch inappropriate" item is not hidden for valid configuration.

I do not mind if you commit any variant.
diff --git a/doc/org-manual.org b/doc/org-manual.org
index a38dbec4a..b62c52e61 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -10814,9 +10814,11 @@ and verbatim string is not processed for Org specific syntax; it is
 exported verbatim.
 
 #+vindex: org-fontify-emphasized-text
+#+vindex: org-emphasis-alist
 To turn off fontification for marked up text, you can set
-~org-fontify-emphasized-text~ to ~nil~.  To narrow down the list of
-available markup syntax, you can customize ~org-emphasis-alist~.
+~org-fontify-emphasized-text~ to ~nil~.  For more fine-tuned
+fontification consider themes. It is possible to customize
+~org-emphasis-alist~ variable, but it will be deprecated.
 
 ** Subscripts and Superscripts
 :PROPERTIES:
diff --git a/lisp/org.el b/lisp/org.el
index cb1b58c51..ea62ae0b2 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)
@@ -3779,23 +3798,41 @@ You need to reload Org or to restart Emacs after setting this.")
     ("~" org-code verbatim)
     ("+" (:strike-through t)))
   "Alist of characters and faces to emphasize text.
+Warning! This variable will be deprecated in favor of themes.
+
 Text starting and ending with a special character will be emphasized,
 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.

Reply via email to