]> git.eshelyaron.com Git - emacs.git/commitdiff
Better support for Elisp icon names.
authorEshel Yaron <me@eshelyaron.com>
Tue, 22 Apr 2025 21:18:13 +0000 (23:18 +0200)
committerEshel Yaron <me@eshelyaron.com>
Tue, 22 Apr 2025 21:18:13 +0000 (23:18 +0200)
lisp/emacs-lisp/find-func.el
lisp/emacs-lisp/icons.el
lisp/emacs-lisp/scope.el
lisp/loadhist.el
lisp/progmodes/elisp-mode.el

index 13c58482697c14496a478c4faf5f151bb640bf52..6d7dede9d8b7e2c0861a59d34a00e9712ad76e3a 100644 (file)
@@ -82,6 +82,9 @@ Please send improvements and fixes to the maintainer."
 (defvar find-symbol-type-regexp
   (concat "^\\s-*(scope-define-symbol-type" find-function-space-re "%s\\(\\s-\\|$\\)"))
 
+(defvar find-icon-regexp
+  (concat "^\\s-*(define-icon" find-function-space-re "%s\\(\\s-\\|$\\)"))
+
 (defvar find-widget-regexp
   (concat "^\\s-*(define-widget" find-function-space-re "%s\\(\\s-\\|$\\)"))
 
@@ -144,6 +147,7 @@ should insert the feature name."
     (ert-deftest . find-ert-deftest-regexp)
     (define-widget . find-widget-regexp)
     (define-error . find-error-regexp)
+    (define-icon . find-icon-regexp)
     (define-symbol-type . find-symbol-type-regexp))
   "Alist mapping definition types into regexp variables.
 Each regexp variable's value should actually be a format string
index 3ad91aea6f7ee7dbdb3b58644ebca611aa996950..d6679a59311d0eb2e1f6c364c30dccd50b4deae7 100644 (file)
@@ -83,6 +83,7 @@ the icon is used as a button and you click it."
 
 (defun icons--register (name parent spec doc keywords)
   (put name 'icon--properties (list parent spec doc keywords))
+  (add-to-list 'current-load-list `(define-icon . ,name))
   (custom-add-to-group
    (or (plist-get keywords :group)
        (custom-current-group))
@@ -245,7 +246,7 @@ present if the icon is represented by an image."
 (defun describe-icon (icon)
   "Pop to a buffer to describe ICON."
   (interactive
-   (list (intern (completing-read "Describe icon: " obarray 'iconp t))))
+   (list (intern (completing-read "Describe icon: " obarray #'iconp t))))
   (let ((icon (if (stringp icon) (intern icon) icon))
         (help-buffer-under-preparation t))
     (help-setup-xref (list #'describe-icon icon)
index b7d488aa5c3bebda5049ad2bd6a76de238861e0e..0b3d64632ad0542834b25c97fa8b83ece7d4b910 100644 (file)
   :help (lambda (beg _end def)
           (if (equal beg def) "Block definition" "Block")))
 
+(scope-define-symbol-type icon ()
+  :doc "Icon names."
+  :face 'font-lock-type-face
+  :help (constantly "Icon")
+  :completion (constantly (lambda (sym) (get sym 'icon--properties)))
+  :namespace 'icon)
+
+(scope-define-symbol-type deficon ()
+  :doc "Icon definitions."
+  :face 'font-lock-type-face
+  :help (constantly "Icon definition")
+  :imenu "Icon"
+  :namespace 'icon)
+
 (defvar scope-counter nil)
 
 (defvar scope-local-functions nil)
@@ -1658,9 +1672,21 @@ a (possibly empty) list of safe macros.")
 (scope-define-function-analyzer scope-report (type &rest _)
   (when-let ((q (scope--unqoute type))) (scope-report-s q 'symbol-type)))
 
-(scope-define-function-analyzer scope-report-s (_sym type)
+(scope-define-function-analyzer scope-report-s (&optional _sym type)
   (when-let ((q (scope--unqoute type))) (scope-report-s q 'symbol-type)))
 
+(scope-define-function-analyzer icons--register (&optional name parent _spec _doc kws)
+  (when-let ((q (scope--unqoute name))) (scope-report-s q 'deficon))
+  (when-let ((q (scope--unqoute parent))) (scope-report-s q 'icon))
+  (when-let ((q (scope--unqoute kws)))
+    (while-let ((kw (car-safe q))
+                (bkw (scope-sym-bare kw))
+                ((keywordp bkw)))
+      (scope-report-s kw 'constant)
+      (case bkw
+        (:group (scope-report-s (cadr q) 'group)))
+      (setq q (cddr q)))))
+
 (scope-define-macro-analyzer define-globalized-minor-mode (l global mode turn-on &rest body)
   (scope-report-s mode 'function)
   (scope-report-s turn-on 'function)
index ff531403c6cda006d905d758d8fbef7bc22c8a29..3e18eb1da66f88337a556d04eccc05e8068b21c6 100644 (file)
@@ -244,6 +244,9 @@ unloading."
     (put name 'scope-parent-types nil)
     (put name 'scope-type-properties nil)))
 
+(cl-defmethod loadhist-unload-element ((x (head define-icon)))
+  (let ((name (cdr x))) (put name 'icon--properties nil)))
+
 ;;;###autoload
 (defun unload-feature (feature &optional force)
   "Unload the library that provided FEATURE.
index cc780138e1bcfe019b759a52f17e676b42d3bc84..8965e5d6587f82eff715cdae39000821e3e7927a 100644 (file)
@@ -1115,6 +1115,7 @@ confidence."
                  (feature '(feature))
                  (widget-type '(widget-type))
                  (condition '(condition))
+                 (icon '(deficon icon))
                  (variable '(defvar variable constant))
                  (symbol-type '(symbol-type symbol-type-definition))
                  (function '(defun function macro special-form major-mode)))))
@@ -1190,6 +1191,7 @@ confidence."
              ('face '(defface))
              ('feature '(feature))
              ('condition '(define-error))
+             ('icon '(define-icon))
              ('symbol-type '(define-symbol-type))
              ('widget-type '(define-widget)))))
       (cl-loop for d in definitions
@@ -1243,6 +1245,10 @@ confidence."
         (when-let ((file (find-lisp-object-file-name symbol 'define-error)))
           (push (elisp--xref-make-xref 'define-error symbol file) xrefs)))
 
+      (when (get symbol 'icon--properties)
+        (when-let ((file (find-lisp-object-file-name symbol 'define-icon)))
+          (push (elisp--xref-make-xref 'define-icon symbol file) xrefs)))
+
       (when (scope-symbol-type-p symbol)
         (when-let ((file (find-lisp-object-file-name symbol 'define-symbol-type)))
           (push (elisp--xref-make-xref 'define-symbol-type symbol file) xrefs)))
@@ -2688,6 +2694,7 @@ of TARGET."
      (if (time-less-p (or (car cached) 0) modtime)
          (puthash file (cons modtime
                              (with-work-buffer
+                               (setq lexical-binding t)
                                (insert-file-contents file)
                                (elisp-symbols-index-1 file)))
                   elisp-symbols-index-cache)