From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kaushal Subject: Re: Reason for org meta line fontification to have the highest priority? Date: Wed, 13 May 2015 21:56:07 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a113a789aa0d2a50515fdad1f Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44687) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsedO-00072L-93 for emacs-orgmode@gnu.org; Wed, 13 May 2015 17:56:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YsedM-0007Qx-Gp for emacs-orgmode@gnu.org; Wed, 13 May 2015 17:56:10 -0400 Received: from mail-yk0-x232.google.com ([2607:f8b0:4002:c07::232]:33783) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsedM-0007Qb-9F for emacs-orgmode@gnu.org; Wed, 13 May 2015 17:56:08 -0400 Received: by ykeo186 with SMTP id o186so18673980yke.0 for ; Wed, 13 May 2015 14:56:07 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: "emacs-orgmode@gnu.org" --001a113a789aa0d2a50515fdad1f Content-Type: text/plain; charset=ISO-8859-1 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 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)) > > --001a113a789aa0d2a50515fdad1f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Alright, I see an issue that org style links in code block= s also get fontified as links. But then isn't it a better idea to separ= ate out the fontification of code blocks (in which you don't want to fo= ntify 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.co= m> 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 fac= e because the meta line fontification is done AFTER link fontification.

Is there a specific reason why the meta line fontific= ation has to be done at the very last?

I have edit= ed this function (just moved the meta line fontification above link fontifi= cation) and now I can see a link fontification within the caption.

I would like to understand if there is a reason why one sh= ould not move this order.

Thanks!

(defun org-set-font-lock-defaults ()
=A0 "Set = font lock defaults for the current buffer."
=A0 (let* ((em o= rg-fontify-emphasized-text)
= (lk org-activate-links)
(org-font-lock-extra-keywords
=A0(list
=A0 ;; Call the hook
=A0 '(org-font-lock-hook)
=A0 ;; Headlines
=A0 `(,(if org-fontify-whole-heading-line
=A0"^\\(\\**\\)\\(\\= * \\)\\(.*\n?\\)"
"^\\(\\**\\)\\(\\* \\)\\(.*\\)")
=A0 =A0 (1 (org-get-level-face 1))
=A0 =A0 (2 (org-get-level-face = 2))
=A0 =A0 (3 (org= -get-level-face 3)))
=A0 ;; Table lines
=A0 '("^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)"
=A0 =A0 (1 'org-table t))
=A0 ;; Table internal= s
=A0 '("^= [ \t]*|\\(?:.*?|\\)? *\\(:?=3D[^|\n]*\\)" (1 'org-formula t))
=A0 '("^[ \t]*= | *\\([#*]\\) *|" (1 'org-formula t))
=A0 '("^[ \t]*|\\( *\\([$!_^/]\\) *|.*= \\)|" (1 'org-formula t))
=A0 '("| *\\(<[lrc]?[0-9]*>\\)" (1 '= ;org-formula t))
= =A0 ;; Drawers
=A0 = (list org-drawer-regexp '(0 'org-special-keyword t))
=A0 (list "^[ \t]*:END:"= ; '(0 'org-special-keyword t))
=A0 ;; Properties
=A0 (list org-property-re
'(1 'org-special-keyword t)
'(3 'org-property-valu= e t))
=A0 =A0 =A0 =A0 =A0 =A0;; Begin edit by KM
=A0 ;; Blocks and meta lines
<= div>=A0 =A0 =A0 =A0 =A0 =A0;; Move meta line fontification BEFORE the link = fontification so that
=A0 =A0 =A0 =A0 =A0 =A0;; if meta lines lik= e figure or table captions have links then the
=A0 =A0 =A0 =A0 = =A0 =A0;; link fontification can override the meta line fontification
=
=A0 '(org-fontify-me= ta-lines-and-blocks)
=A0 =A0 =A0 =A0 =A0 =A0;; End edit by KM
=A0 ;; Links
=A0 (if (memq 'tag lk) &= #39;(org-activate-tags (1 'org-tag prepend)))
=A0 (if (memq 'angle lk) '(org-activ= ate-angle-links (0 'org-link t)))
=A0 (if (memq 'plain lk) '(org-activate-plain-li= nks (0 'org-link t)))
<= /span> =A0 (if (memq 'bracket lk) '(org-activate-bracket-links (0 &= #39;org-link t)))
= =A0 (if (memq 'radio lk) '(org-activate-target-links (0 'org-li= nk t)))
=A0 (if (me= mq 'date lk) '(org-activate-dates (0 'org-date t)))
<= span style=3D"white-space:pre-wrap"> =A0 (if (memq 'footnote lk= ) '(org-activate-footnote-links))
=A0 =A0 =A0 =A0 =A0 =A0;; T= argets.
=A0 =A0 =A0 =A0 =A0 =A0(list org-any-target-regexp '(= 0 'org-target t))
=A0 ;; Diary sexps.
=A0 '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org= -sexp-date t))
=A0 = ;; Macro
=A0 '(= "{{{.+}}}" (0 'org-macro t))
=A0 '(org-hide-wide-columns (0 nil append))
=A0 ;; TODO keyword
=A0 (list (format org= -heading-keyword-regexp-format
org-todo-regexp)
'(2 (org-get-todo-face 2) t))
=A0 ;; DONE
=A0 (if org-fontify-done-headline
=A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0(list (format org-heading-keyword-regexp-format
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(concat
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "\= \(?:"
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 (mapconcat 'regexp-quote org-done-keywords "\\|")
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "\\= )"))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'(2 '= ;org-headline-done t))
=A0 =A0 nil)
= =A0 ;; Priorities
= =A0 '(org-font-lock-add-priority-faces)
=A0 ;; Tags
=A0 '(org-font-lock-add-tag-faces)
=A0 ;; Tags groups
=A0 (if (and org-group-tags org-tag-g= roups-alist)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(list (concat org-out= line-regexp-bol ".+\\(:"
=A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(regexp-opt (mapcar 'car org-tag-groups-= alist))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0":\\).*$")
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0'(1 'org-tag-group prepend)))
=A0 ;; Special keywords
=A0 (list (concat "\\<" org-deadlin= e-string) '(0 'org-special-keyword t))
=A0 (list (concat "\\<" org-schedu= led-string) '(0 'org-special-keyword t))
=A0 (list (concat "\\<" org-clos= ed-string) '(0 'org-special-keyword t))
=A0 (list (concat "\\<" org-clock= -string) '(0 'org-special-keyword t))
=A0 ;; Emphasis
=A0 (if em
=A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0(if (featurep 'xemacs)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0'(org-do-emphasis-faces (0 nil append))
=A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0'(org-do-emphasis-faces)))
=A0 ;; Checkboxes
=A0 '("^[ \t]*\\(?:[-+*]\\|[0-9]+[.)= ]\\)[ \t]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\(\\[[- X]\\]\\)"= ;
=A0 =A0 1 'or= g-checkbox prepend)
= =A0 (if (cdr (assq 'checkbox org-list-automatic-rules))
=A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0'("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\= )/\\([0-9]*\\)\\]"
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(0 (or= g-get-checkbox-statistics-face) t)))
=A0 ;; Description list items
=A0 '("^[ \t]*[-+*][ \t]+\\(.*?[ \t]+= ::\\)\\([ \t]+\\|$\\)"
= =A0 =A0 1 'org-list-dt prepend)
=A0 ;; ARCHIVEd headings
=A0 (list (concat
=A0org-outline-regexp-bol
=A0"\\(.*:" org-archive-t= ag ":.*\\)")
'(1 'org-archived prepend))
=A0 ;; Specials
=A0 '(org-do-latex-and-related)
=A0 '(org-fontify-entities)
=A0 '(org-raise-script= s)
=A0 ;; Code
=A0 '(org-activate-= code (1 'org-code t))
<= /span> =A0 ;; COMMENT
=A0 (list (format org-heading-keyword-regexp-format
(concat "\\("
org-comment-string "\\|&= quot; org-quote-string
<= /span> "\\)"))
<= /span> '(2 'org-special-keyword t))
=A0 =A0 =A0 =A0 =A0 = =A0;; '(org-fontify-meta-lines-and-blocks) ; Edited by KM
=A0= =A0 =A0 =A0 =A0 =A0)))
=A0 =A0 (setq org-font-lock-extra-keyword= s (delq nil org-font-lock-extra-keywords))
=A0 =A0 (run-hooks = 9;org-font-lock-set-keywords-hook)
=A0 =A0 ;; Now set the full fo= nt-lock-keywords
=A0 =A0 (org-set-local 'org-font-lock-keywor= ds org-font-lock-extra-keywords)
=A0 =A0 (org-set-local 'font= -lock-defaults
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'(org-f= ont-lock-keywords t nil nil backward-paragraph))
=A0 =A0 (kill-lo= cal-variable 'font-lock-keywords) nil))

--001a113a789aa0d2a50515fdad1f--