emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Using backticks for the inline code delimeter?
@ 2021-03-31 18:48 George Mauer
  2021-03-31 19:16 ` autofrettage
                   ` (5 more replies)
  0 siblings, 6 replies; 40+ messages in thread
From: George Mauer @ 2021-03-31 18:48 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 736 bytes --]

Markdown uses backticks to denote inline code which should get special
(typically monospace) formatting, org uses the tilde character.

Now I know that org is not markdown, is far more powerful than markdown,
and is not (mostly) the same use cases as markdown. But this one use case
*does* overlap. And the backticks thing is becoming so ingrained that not
only do I reach for it all the time, but I've seen it crop up on this very
mailing list and even in some README.org documents.

I would like to submit that org consider adopting backticks as an alternate
way of denoting inline code.

Aside from any official movement, I would like to add this to my own files
- is there a straightforward way to extend the org parser to do this?

[-- Attachment #2: Type: text/html, Size: 848 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread
* Re: Using backticks for the inline code delimeter?
@ 2022-03-19  3:17 chris
  2022-03-19  3:24 ` chris
  0 siblings, 1 reply; 40+ messages in thread
From: chris @ 2022-03-19  3:17 UTC (permalink / raw)
  To: orgmode

[-- Attachment #1: Type: text/plain, Size: 4480 bytes --]

> George Mauer writes:
>> is there a straightforward way to extend the org parser to do this?
> I don't think so. It seems the emphasis markers are hard-coded
> in various places.
>
> From a quick look at the code, you'd have to customize
> `org-emphasis-alist` and redefine `org-set-emph-re`  and
> `org-do-emphasis-faces`. Maybe that'd be enough.
>

I did just what you said, and I've inserted what's bellow, somewhere in my `init.org` / 
`init.el`, before anything `org-mode` related (save for two `hook`):
(Note it is an almost exact copy from `org.el`, I've only changed a few characters. And 
added the `advice-add override`.)

#+begin_src emacs-lisp
  (defun org-set-emph-re-fixed (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)))
        (setq org-emph-re (format template "*/_+"))
        (setq org-verbatim-re (format template "=~`")))))

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

#+begin_src emacs-lisp
  (defun org-do-emphasis-faces-fixed (limit)
    "Run through the buffer and emphasize strings."
    (let ((quick-re (format "\\([%s]\\|^\\)\\([~`=*/_+]\\)"
                            (car org-emphasis-regexp-components))))
      (catch :exit
        (while (re-search-forward quick-re limit t)
          (let* ((marker (match-string 2))
                 (verbatim? (member marker '("~" "`" "="))))
            (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))
                          (m (if org-hide-emphasis-markers 4 2)))
                (font-lock-prepend-text-property
                 (match-beginning m) (match-end m) '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 (and org-hide-emphasis-markers
                           (not (org-at-comment-p)))
                  (add-text-properties (match-end 4) (match-beginning 5)
                                       '(invisible t))
                  (add-text-properties (match-beginning 3) (match-end 3)
                                       '(invisible t)))
                (throw :exit t))))))))

[-- Attachment #2: Type: text/html, Size: 21198 bytes --]

^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2022-03-19  3:26 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-31 18:48 Using backticks for the inline code delimeter? George Mauer
2021-03-31 19:16 ` autofrettage
2021-03-31 19:19   ` Timothy
2021-04-01  6:03     ` Marcin Borkowski
2021-04-20 13:30     ` Matt Price
2021-04-20 20:24       ` John Kitchin
2021-04-21 22:37         ` Matt Price
2021-04-20 22:30       ` Tim Cross
2021-04-21 19:22         ` John Kitchin
2021-04-21 19:49           ` Tim Cross
2021-03-31 19:24 ` Sébastien Miquel
2021-04-01 16:49   ` Maxim Nikulin
2021-04-01 17:05     ` Timothy
2021-04-01 18:43       ` Samuel Wales
2021-04-01 23:14         ` Tim Cross
2021-04-01 23:30           ` Joost Kremers
2021-04-02  0:28             ` Tim Cross
2021-04-04  1:13               ` Tom Gillespie
2021-04-04 10:03                 ` Joost Kremers
2021-04-04 12:19                   ` Nicolas Goaziou
2021-04-04 16:46                     ` Bill Burdick
2021-04-04 17:24                       ` Nicolas Goaziou
2021-04-04 19:33                     ` Joost Kremers
2021-04-04 23:06                       ` Nicolas Goaziou
2021-04-06 15:03                         ` Maxim Nikulin
2021-04-19  9:27                           ` Nicolas Goaziou
2021-03-31 19:28 ` Timothy
2021-03-31 19:55   ` autofrettage
2021-03-31 20:31 ` Diego Zamboni
2021-03-31 21:51   ` George Mauer
2021-03-31 22:27     ` Dr. Arne Babenhauserheide
2021-03-31 22:38       ` Tim Cross
2021-04-01  0:25         ` Samuel Wales
2021-04-01  1:11 ` Bill Burdick
2021-04-01  3:42 ` Greg Minshall
2021-04-01  9:32   ` autofrettage
2021-04-02 11:23     ` Andreas Eder
2021-04-04 17:06       ` Maxim Nikulin
  -- strict thread matches above, loose matches on Subject: below --
2022-03-19  3:17 chris
2022-03-19  3:24 ` chris

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).