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

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

[elpa] externals/ebdb 957fc1b 157/350: Implement popping of buffer searc


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb 957fc1b 157/350: Implement popping of buffer search history
Date: Mon, 14 Aug 2017 11:46:26 -0400 (EDT)

branch: externals/ebdb
commit 957fc1bc2dd2a58c88f7b141512412b61259c9dd
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>

    Implement popping of buffer search history
    
    Closes #12
    
    * ebdb-com.el (ebdb-search-history): New buffer-local defvar holding
      search history for this EBDB buffer.  Search history is a list of
      record uuids.
      (ebdb-search-display): When running user-initiated searches in an
      existing EBDB buffer, store the list of previously-displayed
      records.
      (ebdb-display-records): Don't call `ebdb-mode' if we're already in
      it, as that wipes local variables.
      (ebdb-search-pop): New command for popping history.
    * ebdb.org: Document in manual.
---
 ebdb-com.el | 35 ++++++++++++++++++++++++++++++-----
 ebdb.org    |  5 +++++
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/ebdb-com.el b/ebdb-com.el
index 2cac6f0..1a51e41 100644
--- a/ebdb-com.el
+++ b/ebdb-com.el
@@ -160,6 +160,14 @@ Used by `ebdb-mouse-menu'."
 In the *EBDB* buffers it includes the records that are actually displayed
 and its elements are (RECORD DISPLAY-FORMAT MARKER-POS MARK).")
 
+(defvar-local ebdb-search-history nil
+  "A list of lists of previously-displayed EBDB records in this buffer.
+
+For each search in a user-initiated EBDB buffer, the
+previously-displayed EBDB records are pushed here, as a list of
+UUIDs.  ebdb-mode keybindings make it possible to pop back to
+previous records.")
+
 (defvar ebdb-modeline-info (make-vector 2 nil)
   "Precalculated mode line info for EBDB commands.
 This is a vector [INVERT-M INVERT].
@@ -316,6 +324,7 @@ display information."
     (define-key km (kbd "/ D")         'ebdb-search-database)
     (define-key km (kbd "C-x n w")     'ebdb-display-all-records)
     (define-key km (kbd "C-x n d")     'ebdb-display-current-record)
+    (define-key km (kbd "^")           'ebdb-search-pop)
 
     (define-key km [mouse-3]    'ebdb-mouse-menu)
     (define-key km [mouse-2]    (lambda (event)
@@ -676,7 +685,8 @@ name based on the current major mode."
                   (sort (delete-dups (append records existing))
                         (lambda (x y) (ebdb-record-lessp x y))))))
 
-      (ebdb-mode)
+      (unless (derived-mode-p 'ebdb-mode)
+       (ebdb-mode))
 
       (setq ebdb-records
            (mapcar (lambda (r)
@@ -903,7 +913,8 @@ displayed records."
      ["New creation date" ebdb-creation-newer t]
      ["Creation date = time stamp" ebdb-creation-no-change t]
      "--"
-     ["Invert search" ebdb-search-invert t])
+     ["Invert search" ebdb-search-invert t]
+     ["Pop search history" ebdb-search-pop t])
     ("Mail"
      ["Send mail" ebdb-mail t]
      "--"
@@ -1883,13 +1894,17 @@ appended to existing records, or filtered from existing 
records.
 TYPE is the type of search being conducted (ie, 'name, 'mail,
 'address, etc).  CRIT is the search criteria; often a regexp, but
 not necessarily.  FMT is the optional formatter to use."
-  (let* ((pool (if (eql style 'filter)
-                  (mapcar #'car ebdb-records)
+  (let* ((prev (mapcar #'car ebdb-records))
+        (pool (if (eql style 'filter)
+                  prev
                 (ebdb-records)))
         (invert (ebdb-search-invert-p))
         (recs (ebdb-search pool clauses invert)))
     (if recs
-       (ebdb-display-records recs fmt (eql style 'append))
+       (progn
+         (when prev
+           (push (mapcar #'ebdb-record-uuid prev) ebdb-search-history))
+         (ebdb-display-records recs fmt (eql style 'append)))
       (message "No matching records"))))
 
 ;;;###autoload
@@ -2091,6 +2106,16 @@ FUNCTION is called with one argument, the record, and 
should return
 the record to be displayed or nil otherwise."
   (ebdb-display-records (seq-filter function (ebdb-records)) fmt))
 
+(defun ebdb-search-pop ()
+  "Pop to the last set of EBDB search results."
+  (interactive)
+  (if ebdb-search-history
+      (ebdb-display-records
+       (mapcar (lambda (r)
+                (ebdb-gethash r 'uuid))
+              (pop ebdb-search-history)))
+    (message "No further search history in this buffer.")))
+
 ;;; Send-Mail interface
 
 ;;;###autoload
diff --git a/ebdb.org b/ebdb.org
index 023b479..8bd1a14 100644
--- a/ebdb.org
+++ b/ebdb.org
@@ -368,6 +368,11 @@ Search commands that currently only work with the "/" 
prefix are:
 - "/ d": Search duplicate records
 - "/ D": Prompt for a database and display all records belonging to
   that database
+
+User-created {{{ebuf}}} buffers keep track of search history in that
+buffer.  To pop back to previous searches, use:
+
+- "^": ebdb-search-pop
 ** Marking
 Records can be marked and acted on in bulk.  The "#" key will toggle
 the mark of the record under point.  "M-#" will toggle the marks of



reply via email to

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