emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Savage <nick@nicksavage.ca>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Improve code readability in org-set-font-lock-defaults
Date: Sun, 14 Mar 2021 22:14:38 -0400	[thread overview]
Message-ID: <870e30e8-d912-df41-c5f7-6fa3f9be7fa2@nicksavage.ca> (raw)

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

I'm not sure what the appetite is for small changes like this, but I 
have attached a small patch to improve readability in 
org-set-font-lock-defaults. I was trying to understand how org-emphasize 
worked and came across some code that I thought could be simplified.

If small refactoring patches like this aren't recommended or if I should 
wait until I have larger patches put together first before sending them 
to the list, please let me know.





[-- Attachment #2: 0001-Refactor-org-set-font-lock-defaults-to-improve-code-.patch --]
[-- Type: text/x-patch, Size: 2390 bytes --]

From a7d5e226dd3b377edcc9c97dd83a8445ae67d952 Mon Sep 17 00:00:00 2001
From: Nicholas Savage <nick@nicksavage.ca>
Date: Sun, 14 Mar 2021 21:47:57 -0400
Subject: [PATCH] Refactor org-set-font-lock-defaults to improve code
 readability

* org.el (org-set-font-lock-defaults): Reduce number of local
variables to improve code readability.
---
 lisp/org.el | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 28596558b..d3c043a0c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5614,9 +5614,7 @@ needs to be inserted at a specific position in the font-lock sequence.")
 
 (defun org-set-font-lock-defaults ()
   "Set font lock defaults for the current buffer."
-  (let* ((em org-fontify-emphasized-text)
-	 (lk org-highlight-links)
-	 (org-font-lock-extra-keywords
+  (let ((org-font-lock-extra-keywords
 	  (list
 	   ;; Call the hook
 	   '(org-font-lock-hook)
@@ -5643,10 +5641,10 @@ needs to be inserted at a specific position in the font-lock sequence.")
 	   '(org-fontify-drawers)
 	   ;; Link related fontification.
 	   '(org-activate-links)
-	   (when (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend)))
-	   (when (memq 'radio lk) '(org-activate-target-links (1 'org-link t)))
-	   (when (memq 'date lk) '(org-activate-dates (0 'org-date t)))
-	   (when (memq 'footnote lk) '(org-activate-footnote-links))
+	   (when (memq 'tag org-highlight-links) '(org-activate-tags (1 'org-tag prepend)))
+	   (when (memq 'radio org-highlight-links) '(org-activate-target-links (1 'org-link t)))
+	   (when (memq 'date org-highlight-links) '(org-activate-dates (0 'org-date t)))
+	   (when (memq 'footnote org-highlight-links) '(org-activate-footnote-links))
            ;; Targets.
            (list org-radio-target-regexp '(0 'org-target t))
 	   (list org-target-regexp '(0 'org-target t))
@@ -5690,7 +5688,7 @@ needs to be inserted at a specific position in the font-lock sequence.")
 	   (list (concat "\\<" org-closed-string) '(0 'org-special-keyword t))
 	   (list (concat "\\<" org-clock-string) '(0 'org-special-keyword t))
 	   ;; Emphasis
-	   (when em '(org-do-emphasis-faces))
+	   (when org-fontify-emphasized-text '(org-do-emphasis-faces))
 	   ;; Checkboxes
 	   '("^[ \t]*\\(?:[-+*]\\|[0-9]+[.)]\\)[ \t]+\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\(\\[[- X]\\]\\)"
 	     1 'org-checkbox prepend)
-- 
2.20.1


             reply	other threads:[~2021-03-15  2:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15  2:14 Nick Savage [this message]
2021-04-26  7:39 ` [PATCH] Improve code readability in org-set-font-lock-defaults Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=870e30e8-d912-df41-c5f7-6fa3f9be7fa2@nicksavage.ca \
    --to=nick@nicksavage.ca \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).