[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5] org.el: Warning for unsupported markers in `org-set-emphasis-
From: |
Ihor Radchenko |
Subject: |
[PATCH v5] org.el: Warning for unsupported markers in `org-set-emphasis-alist' |
Date: |
Thu, 02 Feb 2023 10:53:20 +0000 |
Ihor Radchenko <yantar92@posteo.net> writes:
>> 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.
I further improved the patch adding variable watcher. This should catch
everything. See the attached.
Let me know if there are any objections.
>From 78c61c6cc6fe95ab4d661c86ee8b3902a499cd0e Mon Sep 17 00:00:00 2001
Message-Id:
<78c61c6cc6fe95ab4d661c86ee8b3902a499cd0e.1675335125.git.yantar92@posteo.net>
From: Max Nikulin <manikulin@gmail.com>
Date: Mon, 22 Nov 2021 23:56:15 +0700
Subject: [PATCH v5] org.el: Warn about unsupported markers in
`org-set-emphasis-alist'
* lisp/org.el (org-emphasis-alist): Change custom variable type
definition. Remove unused third list entry from the default value.
(org-emphasis-alist--check-value): New function used to warn the user
when unsupported value is set. The function is used via
`add-variable-watcher'.
Attempts to introduce new markers have been discussed enough times to
add some code that should prevent wasting of time.
Link: https://orgmode.org/list/878rxoa6lk.fsf@localhost
---
lisp/org.el | 56 ++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 45 insertions(+), 11 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 1947c63a8..bc879e5d7 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3635,8 +3635,27 @@ (defvar org-verbatim-re nil
(defvar org-emphasis-regexp-components) ; defined just below
(defvar org-emphasis-alist) ; defined just below
+(defun org-emphasis-alist--check-value (symbol value &optional operation _)
+ "Verify the VALUE of `org-emphasis-alist' SYMBOL.
+Issue a warning when the value is not supported.
+Optional argument OPERATION is intended for `add-variable-watcher'
+usage, which see."
+ (when (memq operation '(set let))
+ (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 symbol))))))
(defun org-set-emph-re (var val)
- "Set variable and compute the emphasis regular expression."
+ "Set VAR to VAL and compute the emphasis regular expression.
+The function is intended for :set argument of `defcustom' for
+`org-emphasis-alist'."
(set-default-toplevel-value var val)
(when (and (boundp 'org-emphasis-alist)
(boundp 'org-emphasis-regexp-components)
@@ -3674,12 +3693,13 @@ (defvar org-emphasis-regexp-components
You need to reload Org or to restart Emacs after setting this.")
+(add-variable-watcher 'org-emphasis-alist #'org-emphasis-alist--check-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,
@@ -3687,18 +3707,32 @@ (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")
+ :package-version '(Org . "9.7")
: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.39.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>
- [PATCH v5] org.el: Warning for unsupported markers in `org-set-emphasis-alist',
Ihor Radchenko <=