emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat a793b0b6e9 05/10: Extract font-locking into comp


From: ELPA Syncer
Subject: [elpa] externals/compat a793b0b6e9 05/10: Extract font-locking into compat-font-lock.el
Date: Mon, 28 Feb 2022 03:57:33 -0500 (EST)

branch: externals/compat
commit a793b0b6e959406c15781c93ca023b4bfd7a71dd
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>

    Extract font-locking into compat-font-lock.el
---
 compat-font-lock.el | 48 ++++++++++++++++++++++++++++++++++++++++++++
 compat-macs.el      |  7 -------
 compat.el           | 57 ++++++++++++++++++++++++++++-------------------------
 3 files changed, 78 insertions(+), 34 deletions(-)

diff --git a/compat-font-lock.el b/compat-font-lock.el
new file mode 100644
index 0000000000..53e9e810b3
--- /dev/null
+++ b/compat-font-lock.el
@@ -0,0 +1,48 @@
+;;; compat-font-lock.el ---                          -*- lexical-binding: t; 
-*-
+
+;; Copyright (C) 2021  Philip Kaludercic
+
+;; Author: Philip Kaludercic <philipk@posteo.net>
+;; Keywords:
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Optional font-locking for `compat' definitions.  Every symbol with
+;; an active compatibility definition will be highlighted.
+;;
+;; Load this file to enable the functionality.
+
+;;; Code:
+
+(eval-and-compile
+  (require 'cl-lib)
+  (require 'compat-macs))
+
+(defvar compat-generate-common-fn)
+(let ((compat-generate-common-fn
+       (lambda (name _def-fn _install-fn check-fn attr _type)
+         (unless (and (plist-get attr :no-highlight)
+                      (funcall check-fn))
+           `(font-lock-add-keywords
+             'emacs-lisp-mode
+             ',`((,(concat "\\_<\\("
+                           (regexp-quote (symbol-name name))
+                           "\\)\\_>")
+                  1 font-lock-preprocessor-face prepend)))))))
+  (load "compat"))
+
+(provide 'compat-font-lock)
+;;; compat-font-lock.el ends here
diff --git a/compat-macs.el b/compat-macs.el
index 75d277421b..d487627a67 100644
--- a/compat-macs.el
+++ b/compat-macs.el
@@ -152,13 +152,6 @@ DEF-FN, INSTALL-FN, CHECK-FN, ATTR and TYPE."
                   (when (get ',name 'compat-def)
                     (error "Duplicate compatibility definition: %s" ',name))
                   (put ',name 'compat-def ',realname)
-                  ,(unless (plist-get attr :no-highlight)
-                     `(font-lock-add-keywords
-                       'emacs-lisp-mode
-                       ',`((,(concat "\\_<\\("
-                                     (regexp-quote (symbol-name name))
-                                     "\\)\\_>")
-                            1 font-lock-preprocessor-face prepend))))
                   ,(funcall install-fn realname version))))
     `(progn
        (put ',realname 'compat-type ',type)
diff --git a/compat.el b/compat.el
index f5147007a6..57ecd9144e 100644
--- a/compat.el
+++ b/compat.el
@@ -122,33 +122,36 @@
 ;; compat-N.M.el directly into the compat.elc.
 (eval-when-compile
   (defmacro compat-insert (version)
-    (cond
-     ((bound-and-true-p compat-testing)
-      `(load ,(format "compat-%s" version)))
-     ((version<= version emacs-version)
-      ;; We don't need to do anything.
-      nil)
-     ((let* ((file (expand-file-name
-                    (format "compat-%s.el" version)
-                    (file-name-directory
-                     (or (and (boundp 'byte-compile-current-file) 
byte-compile-current-file)
-                         load-file-name
-                         buffer-file-name))))
-             (byte-compile-current-file file)
-             defs)
-        (unless (file-exists-p file)
-          (error "Cannot load %S" file))
-        (let ((load-file-name file))
-          (with-temp-buffer
-            (insert-file-contents file)
-            (emacs-lisp-mode)
-            (while (progn
-                     (forward-comment 1)
-                     (not (eobp)))
-              (push (read (current-buffer)) defs))
-            (cons 'progn (nreverse defs)))))))))
-
-(setq-default compat--generate-function 'compat--generate-minimal)
+    (let ((compat--generate-function
+           (if (eq compat--generate-function 'compat--generate-verbose)
+               'compat--generate-minimal
+             compat--generate-function)))
+      (cond
+       ((bound-and-true-p compat-testing)
+        `(load ,(format "compat-%s" version)))
+       ((version<= version emacs-version)
+        ;; We don't need to do anything.
+        nil)
+       ((let* ((file (expand-file-name
+                      (format "compat-%s.el" version)
+                      (file-name-directory
+                       (or (and (boundp 'byte-compile-current-file) 
byte-compile-current-file)
+                           load-file-name
+                           buffer-file-name))))
+               (byte-compile-current-file file)
+               defs)
+          (unless (file-exists-p file)
+            (error "Cannot load %S" file))
+          (let ((load-file-name file))
+            (with-temp-buffer
+              (insert-file-contents file)
+              (emacs-lisp-mode)
+              (while (progn
+                       (forward-comment 1)
+                       (not (eobp)))
+                (push (read (current-buffer)) defs))
+              (cons 'progn (nreverse defs))))))))))
+
 (compat-insert "24.4")
 (compat-insert "25.1")
 (compat-insert "26.1")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]