org-mode/lisp
Tom Gillespie 04d2828ad9 org: Fix verbatim block fontification to end blocks on headlines
* lisp/org.el (org-fontify-meta-lines-and-blocks-1): Enhance regex
for finding the end of blocks (i.e., `beg-of-endline') to detect
headlines (i.e., (rx bol (one-or-more "*") space) so that fontification
matches the behavior of org mode (i.e., that headlines are healines,
even in vertabim).

This change aligns the behavior and the visual appearance of verbatim
blocks that contain headlines. When `font-lock-mode' is enabled this
change makes situations like those in (info "(org) Literal Examples")
literally jump off the page.

Overview of new fontification

Source                | fontification before | fontification after  |
\#+BEGIN_EXAMPLE      | org-block-begin-line | org-block-begin-line |
I look verbatim!      | org-block            | org-block            |
* Org headers in      | org-block            | org-level-1          |
verbatim blocks       | org-block            | nil                  |
** highly accordingly | org-block            | org-level-2          |
\#+END_EXAMPLE        | org-block-end-line   | org-meta-line        |

This commit also makes some improvements to the reability of
org-fontify-meta-lines-and-blocks-1.

1. Use the `rx' macro for better readability. Note that the strings
below return with literal tabs when using `rx'. Expansion included for
reference here.

Begin regex.
old: "^\\([ \t]*#\\(\\(\\+[a-zA-Z]+:?\\| \\|$\\)\\(_\\([a-zA-Z]+\\)\\)?\\)[ \t]*\\(\\([^ \t\n]*\\)[ \t]*\\(.*\\)\\)\\)"
new: "^\\([[:blank:]]*#\\(\\(\\+[A-Za-z]+:?\\|[[:space:]]\\|$\\)\\(_\\([A-Za-z]+\\)\\)?\\)[[:blank:]]*\\(\\([^	\n ]*\\)[[:blank:]]*\\(.*\\)\\)\\)"

End regex. Note match-string call is stringified for documentation here.
old:                        (concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
new: "\\(?:\\(^\\(?:\\*+[[:space:]]\\|[[:blank:]]*#\\+end(match-string 4)\\>.*\\)\\)\\)"

Caption regex:
old: "\\([ \t]*#\\+caption\\(?:\\[.*\\]\\)?:\\)[ \t]*"
new: "\\([[:blank:]]*#\\+caption\\(?:\\[.*]\\)?:\\)[[:blank:]]*"

2. Refactor fontification of #+end blocks for readability and to reduce
the number of calls to point-max to one per branch.

TINYCHANGE
2019-12-19 14:07:33 +01:00
..
Makefile Move link-related core functions out of "org.el" 2019-03-10 18:00:27 +01:00
ob-C.el Fix typos 2019-11-16 17:17:36 -05:00
ob-J.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-R.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-abc.el Backport commit 8832cc5f9 from Emacs 2019-03-17 22:52:48 -04:00
ob-asymptote.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-awk.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-calc.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-clojure.el ob-clojure: Don't tangle with auto prepend ns statement 2019-01-21 21:17:47 +01:00
ob-comint.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-coq.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-core.el ob-core: Respect COMMENTed headlines when expanding noweb references 2019-11-24 10:27:35 +01:00
ob-css.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-ditaa.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-dot.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-ebnf.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-emacs-lisp.el ob-emacs-lisp: Set `lexical-binding' in edit buffers 2019-03-14 15:41:11 +01:00
ob-eshell.el Backport commit 8fb773cc91 from Emacs 2019-12-04 10:37:19 +01:00
ob-eval.el Backport commit 662bee7d7 from Emacs 2019-01-13 12:43:04 -05:00
ob-exp.el Merge branch 'maint' 2019-08-18 17:44:08 -04:00
ob-forth.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-fortran.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-gnuplot.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-groovy.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-haskell.el Backport commit a5b796a87 from Emacs 2019-08-17 09:45:22 -04:00
ob-hledger.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-io.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-java.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-js.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-latex.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-ledger.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-lilypond.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-lisp.el ob-lisp: Strip quotes from result value 2019-09-16 18:38:16 +02:00
ob-lob.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-lua.el Backport commit 6b4a97c1c from Emacs 2019-11-16 17:17:16 -05:00
ob-makefile.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-matlab.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-maxima.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-mscgen.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-ocaml.el ob-ocaml: Support for pretty-printed outputs 2019-10-13 09:44:54 +02:00
ob-octave.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-org.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-perl.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-picolisp.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-plantuml.el ob-plantuml: Fix typo 2019-12-04 18:45:18 +01:00
ob-processing.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-python.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-ref.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-ruby.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-sass.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-scheme.el Backport commit 41ba8231e from Emacs 2019-10-27 15:54:59 -04:00
ob-screen.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-sed.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-shell.el Backport commit 41ba8231e from Emacs 2019-10-27 15:54:59 -04:00
ob-shen.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ob-sql.el ob-sql: Silence byte-compiler 2019-04-16 21:53:15 +02:00
ob-sqlite.el Move `org-fill-template' into "org-macs.el" 2019-03-10 18:00:36 +01:00
ob-stan.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-table.el Update copyright year 2019-01-01 11:50:56 +01:00
ob-tangle.el Fix tangling bug when major mode for LANGUAGE is not `LANGUAGE-mode' 2019-08-30 23:36:00 +02:00
ob-vala.el Update copyright year 2019-01-01 11:50:56 +01:00
ob.el Merge branch 'maint' 2019-01-01 11:54:01 +01:00
ol-bbdb.el Clean up spacing to pass Emacs's pre-commit check 2019-12-03 21:46:54 -05:00
ol-bibtex.el Prefix link-related libraries filenames with "ol" 2019-03-10 18:00:36 +01:00
ol-docview.el Prefix link-related libraries filenames with "ol" 2019-03-10 18:00:36 +01:00
ol-eshell.el Fix org-store-link for eshell 2019-08-22 19:11:04 +02:00
ol-eww.el Prefix link-related libraries filenames with "ol" 2019-03-10 18:00:36 +01:00
ol-gnus.el Merge branch 'maint' 2019-07-23 23:25:05 -04:00
ol-info.el Prefix link-related libraries filenames with "ol" 2019-03-10 18:00:36 +01:00
ol-irc.el Prefix link-related libraries filenames with "ol" 2019-03-10 18:00:36 +01:00
ol-mhe.el Merge branch 'maint' 2019-03-17 22:56:24 -04:00
ol-rmail.el Prefix link-related libraries filenames with "ol" 2019-03-10 18:00:36 +01:00
ol-w3m.el Prefix link-related libraries filenames with "ol" 2019-03-10 18:00:36 +01:00
ol.el Backport commit 94c5eeb1f from Emacs 2019-12-03 21:22:42 -05:00
org-agenda.el Backport commit d1a791f8e from Emacs 2019-12-11 21:19:55 -05:00
org-archive.el Use `org-flag-subtree' instead of `outline-hide-subtree' 2019-05-11 09:48:53 +02:00
org-attach-git.el Fix typos 2019-11-16 17:17:36 -05:00
org-attach.el Backport commit b0f20651e from Emacs 2019-12-11 21:22:50 -05:00
org-capture.el org-capture: Get capture templates from anonymous functions 2019-12-12 22:33:22 +01:00
org-clock.el Merge branch 'maint' 2019-10-27 15:55:30 -04:00
org-colview.el Merge branch 'maint' 2019-08-18 17:44:08 -04:00
org-compat.el Merge branch 'maint' 2019-08-18 17:44:08 -04:00
org-crypt.el Use `org-flag-subtree' instead of `outline-hide-subtree' 2019-05-11 09:48:53 +02:00
org-ctags.el Backport commit 20b858ef1 from Emacs 2019-01-13 12:43:04 -05:00
org-datetree.el Backport commit e14c0d748 from Emacs 2019-03-24 20:39:52 -04:00
org-duration.el Backport commit 476066e89 from Emacs 2019-03-03 22:49:42 -05:00
org-element.el Merge branch 'maint' 2019-08-18 17:44:08 -04:00
org-entities.el Update copyright year 2019-01-01 11:50:56 +01:00
org-faces.el Merge branch 'maint' 2019-09-29 15:49:08 -04:00
org-feed.el Fix typos 2019-11-16 17:17:36 -05:00
org-footnote.el Move link-related core functions out of "org.el" 2019-03-10 18:00:27 +01:00
org-goto.el org-goto: Remove jump to point-min at every start of search 2019-02-09 16:06:06 +01:00
org-habit.el Clean up spacing to pass Emacs's pre-commit check 2019-12-03 21:46:54 -05:00
org-id.el Merge branch 'maint' 2019-09-29 15:49:08 -04:00
org-indent.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
org-inlinetask.el org-inlinetask: remove unused function 2019-03-14 23:41:20 +01:00
org-install.el
org-keys.el Backport commit 8fb773cc91 from Emacs 2019-12-04 10:37:19 +01:00
org-lint.el Merge branch 'maint' 2019-03-14 18:12:08 +01:00
org-list.el org-list: Remove unused defvar 2019-12-15 14:21:34 +01:00
org-macro.el Merge branch 'maint' 2019-04-29 20:49:09 +02:00
org-macs.el Merge branch 'maint' 2019-09-29 15:49:08 -04:00
org-mobile.el Merge branch 'maint' 2019-09-29 15:49:08 -04:00
org-mouse.el Backport commit 3c94c7bc0 and db9c924d3 from Emacs 2019-03-17 22:52:27 -04:00
org-num.el Backport commit 94c5eeb1f from Emacs 2019-12-03 21:22:42 -05:00
org-pcomplete.el org-clock: Add an option to not show the file column in clock report 2019-09-05 18:56:28 +02:00
org-plot.el Fix typos 2019-11-16 17:17:36 -05:00
org-protocol.el Merge branch 'maint' 2019-03-17 22:56:24 -04:00
org-src.el Respect buffer-local value of `org-edit-src-content-indentation' 2019-11-20 22:29:30 +01:00
org-table.el Backport commit d1a791f8e from Emacs 2019-12-11 21:19:55 -05:00
org-tempo.el Update copyright year 2019-01-01 11:50:56 +01:00
org-timer.el org-timer.el: Allow org-timer-set-timer from non-Org buffers 2019-11-17 18:06:00 -05:00
org.el org: Fix verbatim block fontification to end blocks on headlines 2019-12-19 14:07:33 +01:00
ox-ascii.el Add :target option for the TOC keyword 2019-05-30 15:25:46 +02:00
ox-beamer.el Merge branch 'maint' 2019-09-29 15:49:08 -04:00
ox-html.el ox-html: Add equation numbers only for numbered environments 2019-12-09 21:29:56 +01:00
ox-icalendar.el ox-icalendar: Allow ignoring done scheduled or deadlines tasks 2019-09-05 21:54:50 +02:00
ox-latex.el ox-latex: Fix output for Tikz or PGF images 2019-12-07 12:30:19 +01:00
ox-man.el Backport commit 114323226 from Emacs 2019-09-29 15:47:58 -04:00
ox-md.el ox-md: Silence byte compiler 2019-06-05 18:34:38 +02:00
ox-odt.el Fix typos 2019-11-16 17:17:36 -05:00
ox-org.el Update copyright year 2019-01-01 11:50:56 +01:00
ox-publish.el ox-publish: signal org-link-broken for broken fuzzy links 2019-10-08 11:18:13 +02:00
ox-texinfo.el ox-texinfo: Support lettered lists 2019-03-13 15:38:43 +01:00
ox.el ox.el: Replace error with user-error to exit org-export-dispatch 2019-12-09 05:33:00 -05:00