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

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

[elpa] externals/hyperbole c30a718 18/51: Fix out-of-date imenu index af


From: Stefan Monnier
Subject: [elpa] externals/hyperbole c30a718 18/51: Fix out-of-date imenu index after buffer changes
Date: Sun, 12 Jul 2020 18:10:11 -0400 (EDT)

branch: externals/hyperbole
commit c30a7182c61e914d34d67dffee9484447a4d84ea
Author: Bob Weiner <rsw@gnu.org>
Commit: Bob Weiner <rsw@gnu.org>

    Fix out-of-date imenu index after buffer changes
---
 Changes       |  9 ++++++++-
 hmouse-drv.el | 10 +++++-----
 hui-mouse.el  | 51 ++++++++++++++++++++++++++++++++-------------------
 hui-window.el |  2 +-
 4 files changed, 46 insertions(+), 26 deletions(-)

diff --git a/Changes b/Changes
index 3ffbd56..8d18a8f 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,13 @@
+2020-02-01  Bob Weiner  <rsw@gnu.org>
+
+* hui-mouse.el (smart-imenu-item-p): Fixed to handle invalid marker positions 
after buffer changes
+    when imenu-auto-rescan is false.
+
+* hmouse-drv.el (hkey-execute, hkey-help): Simplified with cddr and cadr calls.
+
 2020-01-31  Bob Weiner  <rsw@gnu.org>
 
-* hui-em-but.el (hproperty:set-flash-color): 
+* hui-em-but.el (hproperty:set-flash-color):
                 (hproperty:set-face-after-init): Resolved issue that explicit 
buttons were not
     being highlighted upon load and that explicit and named implicit buttons 
were not flashing
     properly when activated due to improper face settings.
diff --git a/hmouse-drv.el b/hmouse-drv.el
index 9daa51c..631d8f2 100644
--- a/hmouse-drv.el
+++ b/hmouse-drv.el
@@ -378,8 +378,8 @@ Optional prefix arg non-nil means emulate Assist Key rather 
than the
 Action Key.
 
 Works only when running under a window system, not from a dumb terminal."
-  ;; Note: Cannot add start-window as first parameter to this function
-  ;; because it is called like many other functions herein with a
+  ;; Note: Cannot add free variable start-window as first parameter to this
+  ;; function because it is called like many other functions herein with a
   ;; single release-window argument by 'hmouse-choose-windows'.
 
   ;; Cancel any partial drag that may have been recorded.
@@ -753,12 +753,12 @@ Return non-nil iff a non-nil predicate is found."
   (let ((hkey-forms hkey-alist)
        (pred-value) (hkey-action) hkey-form pred)
     (while (and (null pred-value) (setq hkey-form (car hkey-forms)))
-      (if (setq hkey-action (if assist-flag (cdr (cdr hkey-form)) (car (cdr 
hkey-form)))
+      (if (setq hkey-action (if assist-flag (cddr hkey-form) (cadr hkey-form))
                pred (car hkey-form)
                pred-value (eval pred))
          ;; Conditionally debug after Smart Key release and evaluation
          ;; of matching predicate but before hkey-action is executed.
-         (progn (if hkey-debug (hkey-debug))
+         (progn (when hkey-debug (hkey-debug))
                 (eval hkey-action))
        (setq hkey-forms (cdr hkey-forms))))
     pred-value))
@@ -779,7 +779,7 @@ Return non-nil iff associated help documentation is found."
          (setq hkey-forms (cdr hkey-forms))))
     (if pred-value
        (setq call (if assist-flag (cdr (cdr hkey-form))
-                    (car (cdr hkey-form)))
+                    (cadr hkey-form))
              cmd-sym (car call))
       (setq cmd-sym (if assist-flag assist-key-default-function 
action-key-default-function)
            call cmd-sym))
diff --git a/hui-mouse.el b/hui-mouse.el
index 0c3193b..fa289ac 100644
--- a/hui-mouse.el
+++ b/hui-mouse.el
@@ -1205,26 +1205,39 @@ sets `hkey-value' to (identifier . 
identifier-definition-buffer-position)."
        (cdr hkey-value)))
 
 ;; Derived from `imenu' function in the imenu library.
-(defun smart-imenu-item-p (index-item &optional variable-flag)
-  "If INDEX-ITEM is in the current buffer's imenu, return its definition 
marker position, else nil.
-If INDEX-ITEM is both a function and a variable, the function
+(defun smart-imenu-item-p (index-key &optional variable-flag no-recurse-flag)
+  "If INDEX-KEY is in the current buffer's imenu, return its definition marker 
position, else nil.
+If INDEX-KEY is both a function and a variable, the function
 definition is used by default; in such a case, when optional
-VARIABLE-FLAG is non-nil, the variable definition is used instead."
-  (when (stringp index-item)
-    ;; Convert a string to an alist element.
-    (if variable-flag
-       ;; Match to variable definitions only.
-       (setq index-item (assoc index-item
-                               (cdr (assoc "Variables" 
(imenu--make-index-alist)))))
-      ;; First try to match a function definition and if that fails,
-      ;; then allow variable definitions and other types of matches as well.
-      (let ((alist (imenu--make-index-alist)))
-       (setq index-item (or (assoc index-item alist)
-                            ;; Does nothing unless the dash Emacs Lisp
-                            ;; library is available for the -flatten function.
-                            (and (require 'dash nil t)
-                                 (assoc index-item (-flatten alist)))))))
-    (if index-item (cdr index-item))))
+VARIABLE-FLAG is non-nil, the variable definition is used instead.
+NO-RECURSE-FLAG non-nil prevents infinite recursions."
+  (when (stringp index-key)
+    (let (index-item
+         index-position)
+      ;; Convert a string to an alist element.
+      (if variable-flag
+         ;; Match to variable definitions only.
+         (setq index-item (assoc index-key
+                                 (cdr (assoc "Variables" 
(imenu--make-index-alist)))))
+       ;; First try to match a function definition and if that fails,
+       ;; then allow variable definitions and other types of matches as well.
+       (let ((alist (imenu--make-index-alist)))
+         (setq index-item (or (assoc index-key alist)
+                              ;; Does nothing unless the dash Emacs Lisp
+                              ;; library is available for the -flatten 
function.
+                              (and (require 'dash nil t)
+                                   (assoc index-key (-flatten alist)))))))
+      (when index-item
+       (setq index-position (when (markerp (cdr index-item))
+                              (marker-position (cdr index-item))))
+       (if (and (eq index-position 1) (not no-recurse-flag))
+           ;; If index position is 1, this means the index markers have
+           ;; become out of date after buffer edits (likely imenu-auto-rescan
+           ;; is nil), so do a single rescan to try to fix this.
+           (progn (setq imenu--index-alist nil)
+                  (imenu--make-index-alist t)
+                  (smart-imenu-item-p index-key variable-flag t))
+         index-position)))))
 
 ;;; ************************************************************************
 ;;; smart-info functions
diff --git a/hui-window.el b/hui-window.el
index fe35813..737c3e9 100644
--- a/hui-window.el
+++ b/hui-window.el
@@ -72,7 +72,7 @@
 
 (eval-when-compile (defvar assist-flag nil)) ;; Silences free variable 
compiler warnings
 (require 'hycontrol)
-;; For momentary highlighting of buffer/file item lines.
+;; If installed, use pulse library for momentary highlighting of buffer/file 
item lines.
 (require 'pulse nil t)
 
 ;;; ************************************************************************



reply via email to

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