emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] org.el: Warning for unsupported markers in `org-set-emphasis


From: Ihor Radchenko
Subject: Re: [PATCH] org.el: Warning for unsupported markers in `org-set-emphasis-alist'
Date: Sat, 05 Nov 2022 08:21:52 +0000

Max Nikulin <manikulin@gmail.com> writes:

>> 3. Remove verbatim in ("=" org-verbatim verbatim), ("~" org-code
>>     verbatim), and the :type spec.  AFAIU, they are unused. But can you
>>     please double-check?
>
> It seems, before the following commit, verbatim was used to suppress 
> flyspell, but now "~" and "=" are hardcoded.
>
> 9fb2e047d 2016-12-08 09:44:26 +0100 Nicolas Goaziou: Split `org-emph-re' 
> and `org-verbatim-re'
>
> I think, verbatim option should not be removed from `defcustom' :type 
> just now. For some users it might cause fallback to raw lisp value in 
> easy customization UI. Perhaps another warning should be added to the 
> `org-set-emphasis-alist' validator and the option should be labeled as 
> unused in the :type definition.

Makes sense.
What about the attached patch?
The idea is to tag the constant as deprecated.

>From 19f636e0d76dac3e1ca133adfac8bf97dfd52a68 Mon Sep 17 00:00:00 2001
Message-Id: 
<19f636e0d76dac3e1ca133adfac8bf97dfd52a68.1667636440.git.yantar92@posteo.net>
From: Max Nikulin <manikulin@gmail.com>
Date: Mon, 22 Nov 2021 23:56:15 +0700
Subject: [PATCH v4] org.el: Warn about 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.  Remove unused third
list entry from the default value.

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'.

Link: https://orgmode.org/list/878rxoa6lk.fsf@localhost
---
 lisp/org.el | 51 +++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 43 insertions(+), 8 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index d8708f8f2..84ed78ef7 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3628,12 +3628,31 @@ (defvar org-emphasis-regexp-components
 
 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.
+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-default-toplevel-value var value)
+  (let ((unsupported
+        (delq nil
+              (mapcar
+                (lambda (entry)
+                  (let ((marker (car entry)))
+                    (unless (member marker '("*" "/" "_" "=" "~" "+")) 
marker)))
+                value))))
+    (when unsupported
+      (warn "Unsupported markup characters '%s' detected in `%s'"
+           (mapconcat #'identity unsupported " ")
+           (symbol-name var))))
+  value)
+
 (defcustom org-emphasis-alist
   '(("*" bold)
     ("/" italic)
     ("_" underline)
-    ("=" org-verbatim verbatim)
-    ("~" org-code verbatim)
+    ("=" org-verbatim)
+    ("~" org-code)
     ("+" (:strike-through t)))
   "Alist of characters and faces to emphasize text.
 Text starting and ending with a special character will be emphasized,
@@ -3641,18 +3660,34 @@ (defcustom org-emphasis-alist
 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 :tag "Deprecated ignored constant" verbatim)))))
 
 (defvar org-protecting-blocks '("src" "example" "export")
   "Blocks that contain text that is quoted, i.e. not processed as Org syntax.
-- 
2.35.1


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]