* Reason for org meta line fontification to have the highest priority?
@ 2015-05-13 21:52 Kaushal
2015-05-13 21:56 ` Kaushal
0 siblings, 1 reply; 2+ messages in thread
From: Kaushal @ 2015-05-13 21:52 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 5458 bytes --]
Hi,
I came across a situation where I had an org link inside a figure caption.
But the way the org-set-font-lock-defaults is written, the org-link face
gets overridden by org-meta-line face because the meta line fontification
is done AFTER link fontification.
Is there a specific reason why the meta line fontification has to be done
at the very last?
I have edited this function (just moved the meta line fontification above
link fontification) and now I can see a link fontification within the
caption.
I would like to understand if there is a reason why one should not move
this order.
Thanks!
(defun org-set-font-lock-defaults ()
"Set font lock defaults for the current buffer."
(let* ((em org-fontify-emphasized-text)
(lk org-activate-links)
(org-font-lock-extra-keywords
(list
;; Call the hook
'(org-font-lock-hook)
;; Headlines
`(,(if org-fontify-whole-heading-line
"^\\(\\**\\)\\(\\* \\)\\(.*\n?\\)"
"^\\(\\**\\)\\(\\* \\)\\(.*\\)")
(1 (org-get-level-face 1))
(2 (org-get-level-face 2))
(3 (org-get-level-face 3)))
;; Table lines
'("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
(1 'org-table t))
;; Table internals
'("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t))
'("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t))
'("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t))
'("| *\\(<[lrc]?[0-9]*>\\)" (1 'org-formula t))
;; Drawers
(list org-drawer-regexp '(0 'org-special-keyword t))
(list "^[ \t]*:END:" '(0 'org-special-keyword t))
;; Properties
(list org-property-re
'(1 'org-special-keyword t)
'(3 'org-property-value t))
;; Begin edit by KM
;; Blocks and meta lines
;; Move meta line fontification BEFORE the link fontification so
that
;; if meta lines like figure or table captions have links then
the
;; link fontification can override the meta line fontification
'(org-fontify-meta-lines-and-blocks)
;; End edit by KM
;; Links
(if (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend)))
(if (memq 'angle lk) '(org-activate-angle-links (0 'org-link t)))
(if (memq 'plain lk) '(org-activate-plain-links (0 'org-link t)))
(if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t)))
(if (memq 'radio lk) '(org-activate-target-links (0 'org-link t)))
(if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
(if (memq 'footnote lk) '(org-activate-footnote-links))
;; Targets.
(list org-any-target-regexp '(0 'org-target t))
;; Diary sexps.
'("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t))
;; Macro
'("{{{.+}}}" (0 'org-macro t))
'(org-hide-wide-columns (0 nil append))
;; TODO keyword
(list (format org-heading-keyword-regexp-format
org-todo-regexp)
'(2 (org-get-todo-face 2) t))
;; DONE
(if org-fontify-done-headline
(list (format org-heading-keyword-regexp-format
(concat
"\\(?:"
(mapconcat 'regexp-quote org-done-keywords
"\\|")
"\\)"))
'(2 'org-headline-done t))
nil)
;; Priorities
'(org-font-lock-add-priority-faces)
;; Tags
'(org-font-lock-add-tag-faces)
;; Tags groups
(if (and org-group-tags org-tag-groups-alist)
(list (concat org-outline-regexp-bol ".+\\(:"
(regexp-opt (mapcar 'car org-tag-groups-alist))
":\\).*$")
'(1 'org-tag-group prepend)))
;; Special keywords
(list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t))
(list (concat "\\<" org-scheduled-string) '(0 'org-special-keyword t))
(list (concat "\\<" org-closed-string) '(0 'org-special-keyword t))
(list (concat "\\<" org-clock-string) '(0 'org-special-keyword t))
;; Emphasis
(if em
(if (featurep 'xemacs)
'(org-do-emphasis-faces (0 nil append))
'(org-do-emphasis-faces)))
;; Checkboxes
'("^[ \t]*\\(?:[-+*]\\|[0-9]+[.)]\\)[
\t]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\(\\[[- X]\\]\\)"
1 'org-checkbox prepend)
(if (cdr (assq 'checkbox org-list-automatic-rules))
'("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
(0 (org-get-checkbox-statistics-face) t)))
;; Description list items
'("^[ \t]*[-+*][ \t]+\\(.*?[ \t]+::\\)\\([ \t]+\\|$\\)"
1 'org-list-dt prepend)
;; ARCHIVEd headings
(list (concat
org-outline-regexp-bol
"\\(.*:" org-archive-tag ":.*\\)")
'(1 'org-archived prepend))
;; Specials
'(org-do-latex-and-related)
'(org-fontify-entities)
'(org-raise-scripts)
;; Code
'(org-activate-code (1 'org-code t))
;; COMMENT
(list (format org-heading-keyword-regexp-format
(concat "\\("
org-comment-string "\\|" org-quote-string
"\\)"))
'(2 'org-special-keyword t))
;; '(org-fontify-meta-lines-and-blocks) ; Edited by KM
)))
(setq org-font-lock-extra-keywords (delq nil
org-font-lock-extra-keywords))
(run-hooks 'org-font-lock-set-keywords-hook)
;; Now set the full font-lock-keywords
(org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords)
(org-set-local 'font-lock-defaults
'(org-font-lock-keywords t nil nil backward-paragraph))
(kill-local-variable 'font-lock-keywords) nil))
[-- Attachment #2: Type: text/html, Size: 12792 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Reason for org meta line fontification to have the highest priority?
2015-05-13 21:52 Reason for org meta line fontification to have the highest priority? Kaushal
@ 2015-05-13 21:56 ` Kaushal
0 siblings, 0 replies; 2+ messages in thread
From: Kaushal @ 2015-05-13 21:56 UTC (permalink / raw)
To: emacs-orgmode@gnu.org
[-- Attachment #1: Type: text/plain, Size: 6099 bytes --]
Alright, I see an issue that org style links in code blocks also get
fontified as links. But then isn't it a better idea to separate out the
fontification of code blocks (in which you don't want to fontify links) and
stuff like captions (in which you do want to fontify links)?
On Wed, May 13, 2015 at 5:52 PM Kaushal <kaushal.modi@gmail.com> wrote:
> Hi,
>
> I came across a situation where I had an org link inside a figure caption.
>
> But the way the org-set-font-lock-defaults is written, the org-link face
> gets overridden by org-meta-line face because the meta line fontification
> is done AFTER link fontification.
>
> Is there a specific reason why the meta line fontification has to be done
> at the very last?
>
> I have edited this function (just moved the meta line fontification above
> link fontification) and now I can see a link fontification within the
> caption.
>
> I would like to understand if there is a reason why one should not move
> this order.
>
> Thanks!
>
> (defun org-set-font-lock-defaults ()
> "Set font lock defaults for the current buffer."
> (let* ((em org-fontify-emphasized-text)
> (lk org-activate-links)
> (org-font-lock-extra-keywords
> (list
> ;; Call the hook
> '(org-font-lock-hook)
> ;; Headlines
> `(,(if org-fontify-whole-heading-line
> "^\\(\\**\\)\\(\\* \\)\\(.*\n?\\)"
> "^\\(\\**\\)\\(\\* \\)\\(.*\\)")
> (1 (org-get-level-face 1))
> (2 (org-get-level-face 2))
> (3 (org-get-level-face 3)))
> ;; Table lines
> '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
> (1 'org-table t))
> ;; Table internals
> '("^[ \t]*|\\(?:.*?|\\)? *\\(:?=[^|\n]*\\)" (1 'org-formula t))
> '("^[ \t]*| *\\([#*]\\) *|" (1 'org-formula t))
> '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*\\)|" (1 'org-formula t))
> '("| *\\(<[lrc]?[0-9]*>\\)" (1 'org-formula t))
> ;; Drawers
> (list org-drawer-regexp '(0 'org-special-keyword t))
> (list "^[ \t]*:END:" '(0 'org-special-keyword t))
> ;; Properties
> (list org-property-re
> '(1 'org-special-keyword t)
> '(3 'org-property-value t))
> ;; Begin edit by KM
> ;; Blocks and meta lines
> ;; Move meta line fontification BEFORE the link fontification
> so that
> ;; if meta lines like figure or table captions have links then
> the
> ;; link fontification can override the meta line fontification
> '(org-fontify-meta-lines-and-blocks)
> ;; End edit by KM
> ;; Links
> (if (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend)))
> (if (memq 'angle lk) '(org-activate-angle-links (0 'org-link t)))
> (if (memq 'plain lk) '(org-activate-plain-links (0 'org-link t)))
> (if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t)))
> (if (memq 'radio lk) '(org-activate-target-links (0 'org-link t)))
> (if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
> (if (memq 'footnote lk) '(org-activate-footnote-links))
> ;; Targets.
> (list org-any-target-regexp '(0 'org-target t))
> ;; Diary sexps.
> '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t))
> ;; Macro
> '("{{{.+}}}" (0 'org-macro t))
> '(org-hide-wide-columns (0 nil append))
> ;; TODO keyword
> (list (format org-heading-keyword-regexp-format
> org-todo-regexp)
> '(2 (org-get-todo-face 2) t))
> ;; DONE
> (if org-fontify-done-headline
> (list (format org-heading-keyword-regexp-format
> (concat
> "\\(?:"
> (mapconcat 'regexp-quote org-done-keywords
> "\\|")
> "\\)"))
> '(2 'org-headline-done t))
> nil)
> ;; Priorities
> '(org-font-lock-add-priority-faces)
> ;; Tags
> '(org-font-lock-add-tag-faces)
> ;; Tags groups
> (if (and org-group-tags org-tag-groups-alist)
> (list (concat org-outline-regexp-bol ".+\\(:"
> (regexp-opt (mapcar 'car
> org-tag-groups-alist))
> ":\\).*$")
> '(1 'org-tag-group prepend)))
> ;; Special keywords
> (list (concat "\\<" org-deadline-string) '(0 'org-special-keyword t))
> (list (concat "\\<" org-scheduled-string) '(0 'org-special-keyword t))
> (list (concat "\\<" org-closed-string) '(0 'org-special-keyword t))
> (list (concat "\\<" org-clock-string) '(0 'org-special-keyword t))
> ;; Emphasis
> (if em
> (if (featurep 'xemacs)
> '(org-do-emphasis-faces (0 nil append))
> '(org-do-emphasis-faces)))
> ;; Checkboxes
> '("^[ \t]*\\(?:[-+*]\\|[0-9]+[.)]\\)[
> \t]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\(\\[[- X]\\]\\)"
> 1 'org-checkbox prepend)
> (if (cdr (assq 'checkbox org-list-automatic-rules))
> '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
> (0 (org-get-checkbox-statistics-face) t)))
> ;; Description list items
> '("^[ \t]*[-+*][ \t]+\\(.*?[ \t]+::\\)\\([ \t]+\\|$\\)"
> 1 'org-list-dt prepend)
> ;; ARCHIVEd headings
> (list (concat
> org-outline-regexp-bol
> "\\(.*:" org-archive-tag ":.*\\)")
> '(1 'org-archived prepend))
> ;; Specials
> '(org-do-latex-and-related)
> '(org-fontify-entities)
> '(org-raise-scripts)
> ;; Code
> '(org-activate-code (1 'org-code t))
> ;; COMMENT
> (list (format org-heading-keyword-regexp-format
> (concat "\\("
> org-comment-string "\\|" org-quote-string
> "\\)"))
> '(2 'org-special-keyword t))
> ;; '(org-fontify-meta-lines-and-blocks) ; Edited by KM
> )))
> (setq org-font-lock-extra-keywords (delq nil
> org-font-lock-extra-keywords))
> (run-hooks 'org-font-lock-set-keywords-hook)
> ;; Now set the full font-lock-keywords
> (org-set-local 'org-font-lock-keywords org-font-lock-extra-keywords)
> (org-set-local 'font-lock-defaults
> '(org-font-lock-keywords t nil nil backward-paragraph))
> (kill-local-variable 'font-lock-keywords) nil))
>
>
[-- Attachment #2: Type: text/html, Size: 11829 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-05-13 21:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-13 21:52 Reason for org meta line fontification to have the highest priority? Kaushal
2015-05-13 21:56 ` Kaushal
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).