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

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

[elpa] externals/leaf 8d68ff9 30/46: Merge pull request #469 from Z572/f


From: Stefan Monnier
Subject: [elpa] externals/leaf 8d68ff9 30/46: Merge pull request #469 from Z572/find-func
Date: Mon, 15 Mar 2021 22:20:45 -0400 (EDT)

branch: externals/leaf
commit 8d68ff910bf11741192ffad41edfbe726d0333ff
Merge: b07b728 a1442a8
Author: Naoya Yamashita <conao3@gmail.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #469 from Z572/find-func
    
    Added support to find the leaf block.
---
 README.md     |  8 ++++++++
 README.org    |  6 ++++++
 leaf-tests.el | 36 ++++++++++++++++++++++++++++++++----
 leaf.el       | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 92 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md
index e12375a..8280cf7 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,8 @@
   - [:leaf-autoload keyword](#leaf-autoload-keyword)
   - [:leaf-defun keyword](#leaf-defun-keyword)
   - [leaf-defvar](#leaf-defvar)
+- [Tips](#tips)
+  - [leaf-find feature](#leaf-find-feature)
 - [Information](#information)
   - [Donation](#donation)
   - [Community](#community)
@@ -2256,6 +2258,12 @@ Depending on the context, you may find that the function 
is declared in the pack
 When binding to a specific map with: bind, the map variable must be explicitly 
declared with: defvar. This keyword suppresses byte compiler warnings by 
automatically declaring the variable.
 
 
+# Tips
+
+## leaf-find feature
+
+Use `leaf-find` to search a leaf block in the configuration file. like 
`find-library`.
+
 
 # Information
 
diff --git a/README.org b/README.org
index e984449..2803084 100644
--- a/README.org
+++ b/README.org
@@ -56,6 +56,8 @@
   - [[:leaf-protect keyword]]
   - [[:leaf-defer keyword]]
   - [[:leaf-autoload keyword]]
+- [[Tips]]
+  - [[leaf-find feature]]
 - [[Information]]
   - [[Donation]]
   - [[Community]]
@@ -2281,6 +2283,10 @@ When binding to a specific map with: bind, the map 
variable must be
 explicitly declared with: defvar. This keyword suppresses byte
 compiler warnings by automatically declaring the variable.
 
+* Tips
+** leaf-find feature
+Use ~leaf-find~ to search a leaf block in the configuration file. like 
~find-library~.
+
 * Information
 ** Donation
 
diff --git a/leaf-tests.el b/leaf-tests.el
index 1a78e53..e8e4071 100644
--- a/leaf-tests.el
+++ b/leaf-tests.el
@@ -152,7 +152,10 @@ Example:
 
 ;;;; test definition
 
-(setq leaf-expand-minimally t)
+(setq leaf-expand-leaf-protect nil)
+(setq leaf-expand-leaf-defun nil)
+(setq leaf-expand-leaf-defvar nil)
+(setq leaf-expand-leaf-path nil)
 
 (cort-deftest-with-macroexpand leaf/none
   '(((leaf leaf)
@@ -2102,8 +2105,7 @@ Example:
 ;;;; System keywords
 
 (cort-deftest-with-macroexpand-let leaf/leaf-expand-minimally
-    ((leaf-expand-leaf-protect t)
-     (leaf-expand-minimally    t))
+    ((leaf-expand-minimally t))
   '(((leaf leaf
        :config (leaf-init))
      (prog1 'leaf
@@ -2147,7 +2149,7 @@ Example:
        (leaf-init)))))
 
 (cort-deftest-with-macroexpand-let leaf/leaf-protect
-    ((leaf-expand-minimally nil))
+    ((leaf-expand-leaf-protect t))
   '(((leaf leaf
        :config (leaf-init))
      (prog1 'leaf
@@ -2179,6 +2181,32 @@ Example:
                          (format "Error in `leaf' block.  Error msg: %s"
                                  (error-message-string err))))))))
 
+(cort-deftest-with-macroexpand-let leaf/leaf-path
+    ((leaf-expand-leaf-path t))
+  '(((leaf leaf
+       :config (leaf-init))
+     (prog1 'leaf
+       (leaf-handler-leaf-path leaf)
+       (leaf-init)))
+
+    ((leaf leaf
+       :leaf-path nil
+       :config (leaf-init))
+     (prog1 'leaf
+       (leaf-init)))
+
+    ((leaf leaf
+       :leaf-path t nil
+       :config (leaf-init))
+     (prog1 'leaf
+       (leaf-handler-leaf-path leaf)
+       (leaf-init)))
+
+    ((leaf-handler-leaf-path leaf)
+     (let ((file (or load-file-name buffer-file-name 
byte-compile-current-file)))
+       (when file
+         (add-to-list 'leaf--paths (cons 'leaf file)))))))
+
 (cort-deftest-with-macroexpand leaf/leaf-defun
   '(((leaf annotate
        :commands annotate-mode
diff --git a/leaf.el b/leaf.el
index f56235e..c5cedbb 100644
--- a/leaf.el
+++ b/leaf.el
@@ -5,7 +5,7 @@
 ;; Author: Naoya Yamashita <conao3@gmail.com>
 ;; Maintainer: Naoya Yamashita <conao3@gmail.com>
 ;; Keywords: lisp settings
-;; Version: 4.3.5
+;; Version: 4.3.6
 ;; URL: https://github.com/conao3/leaf.el
 ;; Package-Requires: ((emacs "24.1"))
 
@@ -54,6 +54,7 @@
 Same as `list' but this macro does not evaluate any arguments."
   `(quote ,args))
 
+(defvar leaf--paths nil)
 (defvar leaf--raw)
 (defvar leaf--name)
 (defvar leaf--key)
@@ -66,6 +67,7 @@ Same as `list' but this macro does not evaluate any 
arguments."
 (defvar leaf-keywords
   (leaf-list
    :disabled          (unless (eval (car leaf--value)) `(,@leaf--body))
+   :leaf-path         (if (and leaf--body (eval (car leaf--value))) 
`((leaf-handler-leaf-path ,leaf--name) ,@leaf--body) `(,@leaf--body))
    :leaf-protect      (if (and leaf--body (eval (car leaf--value))) 
`((leaf-handler-leaf-protect ,leaf--name ,@leaf--body)) `(,@leaf--body))
    :load-path         `(,@(mapcar (lambda (elm) `(add-to-list 'load-path 
,elm)) leaf--value) ,@leaf--body)
    :load-path*        `(,@(mapcar (lambda (elm) `(add-to-list 'load-path 
(locate-user-emacs-file ,elm))) leaf--value) ,@leaf--body)
@@ -354,7 +356,7 @@ Sort by `leaf-sort-leaf--values-plist' in this order.")
 
 (defcustom leaf-system-defaults (leaf-list
                                  :leaf-autoload t :leaf-defer t :leaf-protect t
-                                 :leaf-defun t :leaf-defvar t)
+                                 :leaf-defun t :leaf-defvar t :leaf-path t)
   "The value for all `leaf' blocks for leaf system."
   :type 'sexp
   :group 'leaf)
@@ -380,7 +382,7 @@ If non-nil, disabled keywords of 
`leaf-expand-minimally-suppress-keywords'."
   :type 'boolean
   :group 'leaf)
 
-(defcustom leaf-expand-minimally-suppress-keywords '(:leaf-protect :leaf-defun 
:leaf-defvar)
+(defcustom leaf-expand-minimally-suppress-keywords '(:leaf-protect :leaf-defun 
:leaf-defvar :leaf-path)
   "Suppress keywords when `leaf-expand-minimally' is non-nil."
   :type 'sexp
   :group 'leaf)
@@ -407,6 +409,13 @@ This variable must be result of `plstore-open'."
   :type 'sexp
   :group 'leaf)
 
+(defcustom leaf-find-regexp ".*([[:space:]]*leaf[[:space:]]+%s"
+  "The regexp used by `leaf-find' to search for a leaf block.
+Note it must contain a `%s' at the place where `format'
+should insert the leaf name."
+  :type 'regexp
+  :group 'leaf)
+
 (defcustom leaf-enable-imenu-support t
   "If non-nil, enable `imenu' integrations.
 Ref: `lisp-imenu-generic-expression'."
@@ -729,6 +738,32 @@ see `alist-get'."
       (display-buffer buf))))
 
 
+;;;; find-function
+
+(eval-after-load 'find-func
+  (lambda ()
+    (defvar find-function-regexp-alist)
+    (add-to-list 'find-function-regexp-alist '(leaf . leaf-find-regexp))))
+
+(defun leaf-find (name)
+  "Find the leaf block of NAME."
+  (interactive
+   (let ((candidates (delete-dups (mapcar #'car leaf--paths))))
+     (if (not candidates)
+         (error "Leaf has no definition informations")
+       (list (completing-read "Find leaf: " (delete-dups (mapcar #'car 
leaf--paths)))))))
+  (require 'find-func)
+  (let* ((name (intern name))
+         (paths (mapcan (lambda (elm) (when (eq name (car elm)) (list (cdr 
elm)))) leaf--paths))
+         (path (if (= (length paths) 1) paths (list (completing-read "Select 
one: " paths))))
+         (location (find-function-search-for-symbol name 'leaf path)))
+    (when location
+      (prog1 (pop-to-buffer (car location))
+        (when (cdr location)
+          (goto-char (cdr location)))
+        (run-hooks 'find-function-after-hook)))))
+
+
 ;;;; Key management
 
 (defvar leaf-key-override-global-map (make-keymap)
@@ -924,6 +959,14 @@ FN also accept list of FN."
                                 "  Error msg: %s")
                               (error-message-string err))))))
 
+(defmacro leaf-handler-leaf-path (name)
+  "Meta handler for :leaf-path for NAME."
+  `(let ((file (or load-file-name
+                   buffer-file-name
+                   byte-compile-current-file)))
+     (when file
+      (add-to-list 'leaf--paths (cons ',name file)))))
+
 (defmacro leaf-handler-package (name pkg _pin)
   "Handler ensure PKG via PIN in NAME leaf block."
   `(unless (package-installed-p ',pkg)



reply via email to

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