emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Re: Using backticks for the inline code delimeter?
@ 2022-03-19  3:17 chris
  2022-03-19  3:24 ` chris
  2023-11-27  7:54 ` Using backticks for the inline code delimiter? (now with `org-publish-all`) chris
  0 siblings, 2 replies; 6+ 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] 6+ messages in thread

* Re: Using backticks for the inline code delimeter?
  2022-03-19  3:17 Using backticks for the inline code delimeter? chris
@ 2022-03-19  3:24 ` chris
  2023-11-27  7:54 ` Using backticks for the inline code delimiter? (now with `org-publish-all`) chris
  1 sibling, 0 replies; 6+ messages in thread
From: chris @ 2022-03-19  3:24 UTC (permalink / raw)
  To: orgmode

email got truncated the 1st time, hope it's bee better this time.

> 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))))))))


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

#+begin_src emacs-lisp
  (custom-set-variables '(org-emphasis-alist
                           '(("*" bold)
                             ("/" italic)
                             ("_" underline)
                             ("=" org-verbatim verbatim)
                             ("`" org-code verbatim)
                             ("~" org-code verbatim)
                             ("+" (:strike-through t)))))
#+end_src

Just before:

#+begin_src emacs-lisp
  (straight-use-package 'org)
#+end_src

And it seems it works.

I've tried the "cosmetic" version from bellow, but it wasn't working so well, 
with either `visual-fill-colum` or `org-indent-mode`?
Well, it wasn't working well. I don't know if the hack above is playing more 
nicely. Because I've only tested it on one example.
Chris

>
> For the cosmetic part, there's this  piece of code from
> https://archive.casouri.cat/note/2020/better-looking-verbatim-markup-in-org-mode/index.html
> that displays org's `=` and `~` markers as ```.
>
> --
> Sébastien Miquel






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

* Re: Using backticks for the inline code delimiter? (now with `org-publish-all`)
  2022-03-19  3:17 Using backticks for the inline code delimeter? chris
  2022-03-19  3:24 ` chris
@ 2023-11-27  7:54 ` chris
  2023-12-04 13:06   ` Ihor Radchenko
  1 sibling, 1 reply; 6+ messages in thread
From: chris @ 2023-11-27  7:54 UTC (permalink / raw)
  To: orgmode

The code below is working fine as long as I stay in `org-mode`. But it shows 
its limitations when I do `M-x org-publish-all`, at which time, instead of 
having the text with style verbatim, I get the text within backticks.

Is there any improvement you could think of that would fix that?
Thanks,
Chris


On Saturday, March 19, 2022 3:17:10 AM UTC you wrote:
> > 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))))))))






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

* Re: Using backticks for the inline code delimiter? (now with `org-publish-all`)
  2023-11-27  7:54 ` Using backticks for the inline code delimiter? (now with `org-publish-all`) chris
@ 2023-12-04 13:06   ` Ihor Radchenko
  2023-12-07  2:02     ` chris
  0 siblings, 1 reply; 6+ messages in thread
From: Ihor Radchenko @ 2023-12-04 13:06 UTC (permalink / raw)
  To: chris; +Cc: orgmode

chris <inkbottle007@gmail.com> writes:

> The code below is working fine as long as I stay in `org-mode`. But it shows 
> its limitations when I do `M-x org-publish-all`, at which time, instead of 
> having the text with style verbatim, I get the text within backticks.
>
> Is there any improvement you could think of that would fix that?

You will need to patch the parser in org-element.el.

We do not officially support extending markup syntax. So, even changing
org-element may still leave other bugs. Caveat emptor.

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


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

* Re: Using backticks for the inline code delimiter? (now with `org-publish-all`)
  2023-12-04 13:06   ` Ihor Radchenko
@ 2023-12-07  2:02     ` chris
  2023-12-07 15:13       ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: chris @ 2023-12-07  2:02 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

On Monday, December 4, 2023 1:06:37 PM UTC you wrote:
> chris <inkbottle007@gmail.com> writes:
> > The code below is working fine as long as I stay in `org-mode`. But it
> > shows its limitations when I do `M-x org-publish-all`, at which time,
> > instead of having the text with style verbatim, I get the text within
> > backticks.
> > 
> > Is there any improvement you could think of that would fix that?
> 
> You will need to patch the parser in org-element.el.

Yes, that seems a very good idea.
I've never "patched" emacs before: in the hack I've been using so far I was 
doing some `(advice-add 'org-do-emphasis-faces :override #'org-do-emphasis-
faces-fixed)` thing.
In any case the problem (or part of it) lies in `org-element.el` because I've 
observed the backticks constructions were not recognised as an "element".
But okay, patch emacs, no worries. Since I'm using NixOS, it will take a bit 
of time for me to figure out how to do it the NixOS way.
> 
> We do not officially support extending markup syntax. So, even changing
> org-element may still leave other bugs. Caveat emptor.

The backticks for inline code or verbatim are very pleasing to the eye, and 
are used literally universally.






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

* Re: Using backticks for the inline code delimiter? (now with `org-publish-all`)
  2023-12-07  2:02     ` chris
@ 2023-12-07 15:13       ` Ihor Radchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Ihor Radchenko @ 2023-12-07 15:13 UTC (permalink / raw)
  To: chris; +Cc: emacs-orgmode

chris <inkbottle007@gmail.com> writes:

>> You will need to patch the parser in org-element.el.
>
> Yes, that seems a very good idea.
> I've never "patched" emacs before: in the hack I've been using so far I was 
> doing some `(advice-add 'org-do-emphasis-faces :override #'org-do-emphasis-
> faces-fixed)` thing.

This is an equivalent. Also, you may check out https://github.com/radian-software/el-patch

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


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

end of thread, other threads:[~2023-12-07 15:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-19  3:17 Using backticks for the inline code delimeter? chris
2022-03-19  3:24 ` chris
2023-11-27  7:54 ` Using backticks for the inline code delimiter? (now with `org-publish-all`) chris
2023-12-04 13:06   ` Ihor Radchenko
2023-12-07  2:02     ` chris
2023-12-07 15:13       ` Ihor Radchenko

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