0

Is it possible to exclude the tilde ~ from being interpreted as emphasis-marker in Org-Mode in general?

Meaning not being escaped but being normal interpreted as simple Text?

Emphasis-and-Monospace, Worg

Edit:

The following is now set in my init.el via customize-variable, but doesn't have any effect at all...

Of course, I restarted org-mode. The target is to replace ~ with backtics for code-blocks.

'(org-emphasis-alist
  (quote
  (("*" bold)
   ("/" italic)
   ("_" underline)
   ("=" org-verbatim verbatim)
   ("`" org-code verbatim)
   ("+"
  (:strike-through t)))))
13
  • 1
    Markdown isn’t part of Emacs. Read the documentation for the markdown processor that you are using.
    – db48x
    Nov 21 at 1:03
  • 1
    Details please: who interprets ~ as a markdown marker?
    – NickD
    Nov 21 at 3:04
  • I really don't know... But Emacs treat them as 'org face' so there will be a possibility to configurate... I would guess Emacs passed them to the used Org-Interpreter.
    – OsunSeyi
    Nov 21 at 8:08
  • So you are talking about an Org mode file? ~ is interpreted in Org mode files (as a "verbatim" marker). In other modes however (i.e. generally), it is just a tilde: not interpreted at all. So it's not clear what you want to do: have the tilde not interpreted in Org mode files at all? Have you considered not using Org mode on the file? E.g. changing the major mode to text-mode?
    – NickD
    Nov 21 at 16:49
  • Sorry - I meant in Org-Mode... I use the tilde for lines and can also use = as verbatim-marker. So it would be nice to exclude the tilde from being interpreter as marker.
    – OsunSeyi
    Nov 21 at 21:46
0

org-emphasis-alist wrongly suggests that you could change the emphasis markers. No, that is not the case. It rather gives you the possibility to change the faces for the emphasis markers rigidly given by the syntax specification of org-mode.

Nevertheless, the code below makes some functions of Org-Mode Version 9.2.3 somewhat more general, such that it accepts modifications of the emphasis markers. The modifications are marked by comments starting with ;; Tobias:.

Note, that I used the unspecified third element of the entries of org-emphasis-alist to identify verbatim markers.

(require 'cl-lib)
(require 'org)

(defun org+-emphasis-chars ()
  "Return a list (EMPH VERB) of strings of markers.
EMPH is a string containing all marker chars
for non-verbatim emphasis.
VERB is a string containing all marker chars
for verbatim emphasis."
  (let (emph verb)
    (cl-loop for el in org-emphasis-alist
         if (eq (nth 2 el) 'verbatim)
         do (push (car el) verb)
         else
         do (push (car el) emph))
    (list
     (mapconcat #'identity emph "")
     (mapconcat #'identity verb ""))))

(defvar org+-emph-chars ""
  "String of characters working as emphasis markers.")

(defvar org+-verb-chars ""
  "String of characters working as verbatim markers.")

;; Modified version of `org-set-emph-re':
(defun org+-set-emph-re (var val)
  "Set variable and compute the emphasis regular expression."
  (set var val)
  (when (and (boundp 'org-emphasis-alist)
         (boundp 'org-emphasis-regexp-components)
         org-emphasis-alist org-emphasis-regexp-components)
    (pcase-let*
    ((`(,pre ,post ,border ,body ,nl) org-emphasis-regexp-components)
     (body (if (<= nl 0) body
         (format "%s*?\\(?:\n%s*?\\)\\{0,%d\\}" body body nl)))
     (template
      (format (concat "\\([%s]\\|^\\)" ;before markers
              "\\(\\([%%s]\\)\\([^%s]\\|[^%s]%s[^%s]\\)\\3\\)"
              "\\([%s]\\|$\\)") ;after markers
          pre border border body border post)))
      ;; Tobias: Added:
      (cl-multiple-value-setq (org+-emph-chars org+-verb-chars) (org+-emphasis-chars))
      (setq org-emph-re (format template org+-emph-chars)) ;; Tobias: Replaced literal "*+/_"
      (setq org-verbatim-re (format template org+-verb-chars))))) ;; Tobias: Replaced literal "~="

(advice-add 'org-set-emph-re :override #'org+-set-emph-re)

(org-set-emph-re 'org-emphasis-alist org-emphasis-alist)

;; Modified version of `org-do-emphasis-faces':
(defun org+-do-emphasis-faces (limit)
  "Run through the buffer and emphasize strings."
  (let ((quick-re (format "\\([%s]\\|^\\)\\([%s%s]\\)" ;; Tobias: modified format string
              (car org-emphasis-regexp-components)
              org+-emph-chars ;; Tobias: added
              org+-verb-chars))) ;; Tobias: added
    (catch :exit
      (while (re-search-forward quick-re limit t)
    (let* ((marker (match-string 2))
           (verbatim? (seq-contains org+-verb-chars (string-to-char marker)))) ;; Tobias: replaced (member ... '("=" "~"))
      (when (save-excursion
          (goto-char (match-beginning 0))
          (and
           ;; Do not match table hlines.
           (not (and (equal marker "+")
                 (org-match-line
                  "[ \t]*\\(|[-+]+|?\\|\\+[-+]+\\+\\)[ \t]*$")))
           ;; Do not match headline stars.  Do not consider
           ;; stars of a headline as closing marker for bold
           ;; markup either.
           (not (and (equal marker "*")
                 (save-excursion
                   (forward-char)
                   (skip-chars-backward "*")
                   (looking-at-p org-outline-regexp-bol))))
           ;; Match full emphasis markup regexp.
           (looking-at (if verbatim? org-verbatim-re org-emph-re))
           ;; Do not span over paragraph boundaries.
           (not (string-match-p org-element-paragraph-separate
                    (match-string 2)))
           ;; Do not span over cells in table rows.
           (not (and (save-match-data (org-match-line "[ \t]*|"))
                 (string-match-p "|" (match-string 4))))))
        (pcase-let ((`(,_ ,face ,_) (assoc marker org-emphasis-alist)))
          (font-lock-prepend-text-property
           (match-beginning 2) (match-end 2) 'face face)
          (when verbatim?
        (org-remove-flyspell-overlays-in
         (match-beginning 0) (match-end 0))
        (remove-text-properties (match-beginning 2) (match-end 2)
                    '(display t invisible t intangible t)))
          (add-text-properties (match-beginning 2) (match-end 2)
                   '(font-lock-multiline t org-emphasis t))
          (when org-hide-emphasis-markers
        (add-text-properties (match-end 4) (match-beginning 5)
                     '(invisible org-link))
        (add-text-properties (match-beginning 3) (match-end 3)
                     '(invisible org-link)))
          (throw :exit t))))))))

(advice-add 'org-do-emphasis-faces :override #'org+-do-emphasis-faces)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.