[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/hyperbole 1e14a4c 2/2: Change to lexical passing of sta
From: |
ELPA Syncer |
Subject: |
[elpa] externals/hyperbole 1e14a4c 2/2: Change to lexical passing of start and end arguments to rolo logic |
Date: |
Mon, 6 Dec 2021 01:57:25 -0500 (EST) |
branch: externals/hyperbole
commit 1e14a4cdd71d62c7ce76b813ec480907122f80cc
Author: Bob Weiner <rsw@gnu.org>
Commit: Bob Weiner <rsw@gnu.org>
Change to lexical passing of start and end arguments to rolo logic
---
ChangeLog | 11 ++++
hbut.el | 4 +-
hyrolo-logic.el | 118 ++++++++++++++++-----------------
hyrolo.el | 201 ++++++++++++++++++++++++++++----------------------------
4 files changed, 170 insertions(+), 164 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0209c07..fe475ab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2021-12-05 Bob Weiner <rsw@gnu.org>
+* hyrolo.el (hyrolo-next-match): Handle case when no prior regexp search.
+
+* hyrolo-logic.el (hyrolo-fgrep-logical): Fix improper passage of 'count-only'
+ to 'format'.
+ (hyrolo-map-logic): Pass 'start' and 'end' args to logical
+ operators in the 'eval' 2nd arg which is the lexical environment.
Eliminates
+ use as dynamic variables.
+
+* hyrolo.el (hyrolo-rename): Unify MS Windows default HyRolo file path
+ with Posix OSes to ~/.rolo.otl.
+
* hargs.el (hargs:actype-get): Change to set 'modifying' to t if non-nil
for lower-level function call conformance.
(hargs:iform-read): Change 'modifying' param to 'defaults'.
diff --git a/hbut.el b/hbut.el
index 15ba0bc..835705f 100644
--- a/hbut.el
+++ b/hbut.el
@@ -16,8 +16,8 @@
;;; Other required Elisp libraries
;;; ************************************************************************
-(eval-and-compile (mapc #'require '(elisp-mode help-mode hversion hmoccur hbmap
- htz hbdata hact view)))
+(eval-and-compile (mapc #'require '(elisp-mode help-mode hversion hmoccur
+ hbmap htz hbdata hact view)))
;;; ************************************************************************
;;; Public declarations
diff --git a/hyrolo-logic.el b/hyrolo-logic.el
index d1b5285..2ce5839 100644
--- a/hyrolo-logic.el
+++ b/hyrolo-logic.el
@@ -118,12 +118,12 @@ single argument."
(setq saved-expr expr)))
(setq expr (hypb:replace-match-string
"{\\([^{}]+\\)}" expr "\"\\1\"" nil))
- (setq expr (hypb:replace-match-string "\(| " expr "\(hyrolo-or " t))
- (setq expr (hypb:replace-match-string "\(@ " expr "\(hyrolo-xor " t))
- (setq expr (hypb:replace-match-string "\(! " expr "\(hyrolo-not " t))
- (setq expr (hypb:replace-match-string "\(& " expr "\(hyrolo-and " t))
- (setq expr (format "(hyrolo-logic (quote %s) nil count-only %s %s)"
- expr include-sub-entries no-sub-entries-out))
+ (setq expr (hypb:replace-match-string "\(| " expr "\(hyrolo-or start end
" t))
+ (setq expr (hypb:replace-match-string "\(@ " expr "\(hyrolo-xor start
end " t))
+ (setq expr (hypb:replace-match-string "\(! " expr "\(hyrolo-not start
end " t))
+ (setq expr (hypb:replace-match-string "\(& " expr "\(hyrolo-and start
end " t))
+ (setq expr (format "(hyrolo-logic (quote %s) nil %s %s %s)"
+ expr count-only include-sub-entries
no-sub-entries-out))
(setq total-matches (eval (read expr))))
(if (called-interactively-p 'interactive)
(message "%s matching entr%s found in rolo."
@@ -142,27 +142,25 @@ INCLUDE-SUB-ENTRIES is nil and optional
NO-SUB-ENTRIES-OUT flag is non-nil.
SEXP should use the free variables `start' and `end' which contain the limits
of the region on which it should operate. Returns number of evaluations of
SEXP that matched entries."
- (let ((obuf (current-buffer))
- (display-buf (if count-only
- nil
+ (let* ((display-buf (unless count-only
(prog1 (set-buffer (get-buffer-create
hyrolo-display-buffer))
(setq buffer-read-only nil)
- (erase-buffer)))))
- (let ((result
- (mapcar
- (lambda (in-bufs)
- (hyrolo-map-logic sexp in-bufs count-only include-sub-entries
- no-sub-entries-out))
- (cond ((null in-bufs) hyrolo-file-list)
- ((listp in-bufs) in-bufs)
- ((list in-bufs))))))
- (let ((total-matches (apply '+ result)))
- (unless (or count-only (= total-matches 0))
- (hyrolo-display-matches display-buf))
- total-matches))))
+ (erase-buffer))))
+ (result
+ (mapcar
+ (lambda (in-bufs)
+ (hyrolo-map-logic sexp in-bufs count-only include-sub-entries
+ no-sub-entries-out))
+ (cond ((null in-bufs) hyrolo-file-list)
+ ((listp in-bufs) in-bufs)
+ ((list in-bufs)))))
+ (total-matches (apply '+ result)))
+ (unless (or count-only (= total-matches 0))
+ (hyrolo-display-matches display-buf))
+ total-matches))
(defun hyrolo-map-logic (sexp hyrolo-buf &optional count-only
- include-sub-entries no-sub-entries-out)
+ include-sub-entries _no-sub-entries-out)
"Apply logical SEXP to each entry in HYROLO-BUF and write out matching
entries to `hyrolo-display-buffer'.
If optional COUNT-ONLY is non-nil, don't display entries, return count of
matching entries only. If optional INCLUDE-SUB-ENTRIES flag is non-nil, SEXP
@@ -199,36 +197,30 @@ of applications of SEXP that matched entries."
next-entry-exists nil
curr-entry-level-len (length
(match-string-no-properties hyrolo-entry-group-number))
end (hyrolo-to-entry-end include-sub-entries
curr-entry-level-len))
- (let ((result (eval sexp)))
- (or count-only
- (and result (= num-found 0) hdr-pos
- (let* ((src (or (buffer-file-name hyrolo-buf)
- hyrolo-buf))
- (src-line
- (format
- (concat (if (boundp 'hbut:source-prefix)
- hbut:source-prefix
- "@loc> ")
- "%s")
- (prin1-to-string src))))
- (set-buffer display-buf)
- (goto-char (point-max))
- (if hdr-pos
- (progn
- (insert-buffer-substring
- hyrolo-buf (car hdr-pos) (cdr hdr-pos))
- (insert src-line "\n\n"))
- (insert (format hyrolo-hdr-format src-line)))
- (set-buffer hyrolo-buf))))
+ (let ((result (eval sexp `((start . ,start) (end . ,end)))))
+ (unless count-only
+ (and result (= num-found 0) hdr-pos
+ (let* ((src (or (buffer-file-name hyrolo-buf)
+ hyrolo-buf))
+ (src-line
+ (format
+ (concat (if (boundp 'hbut:source-prefix)
+ hbut:source-prefix
+ "@loc> ")
+ "%s")
+ (prin1-to-string src))))
+ (set-buffer display-buf)
+ (goto-char (point-max))
+ (if hdr-pos
+ (progn
+ (insert-buffer-substring
+ hyrolo-buf (car hdr-pos) (cdr hdr-pos))
+ (insert src-line "\n\n"))
+ (insert (format hyrolo-hdr-format src-line)))
+ (set-buffer hyrolo-buf))))
(if result
(progn (goto-char end)
- (setq num-found (1+ num-found)
- )
- ;; end (if (or include-sub-entries
- ;; no-sub-entries-out)
- ;; end
- ;; (goto-char
(hyrolo-to-entry-end
- ;; t
curr-entry-level-len))))
+ (setq num-found (1+ num-found))
(or count-only
(append-to-buffer display-buf start end)))
(goto-char end-entry-hdr)))))))
@@ -243,7 +235,7 @@ of applications of SEXP that matched entries."
;; Do NOT call the following functions directly.
;; Send them as parts of an expression to `hyrolo-logic'.
-(defun hyrolo-not (&rest pat-list)
+(defun hyrolo-not (start end &rest pat-list)
"Logical <not> rolo entry filter. PAT-LIST is a list of pattern elements.
Each element may be t, nil, or a string."
(let ((pat))
@@ -255,7 +247,7 @@ Each element may be t, nil, or a string."
(setq pat-list (cdr pat-list)))
(not pat-list)))
-(defun hyrolo-or (&rest pat-list)
+(defun hyrolo-or (start end &rest pat-list)
"Logical <or> rolo entry filter. PAT-LIST is a list of pattern elements.
Each element may be t, nil, or a string."
(if (memq t pat-list)
@@ -269,7 +261,7 @@ Each element may be t, nil, or a string."
(setq pat-list (cdr pat-list)))
(if pat-list t nil))))
-(defun hyrolo-xor (&rest pat-list)
+(defun hyrolo-xor (start end &rest pat-list)
"Logical <xor> rolo entry filter. PAT-LIST is a list of pattern elements.
Each element may be t, nil, or a string."
(let ((pat)
@@ -285,7 +277,7 @@ Each element may be t, nil, or a string."
(setq pat-list (cdr pat-list)))
(= matches 1)))
-(defun hyrolo-and (&rest pat-list)
+(defun hyrolo-and (start end &rest pat-list)
"Logical <and> rolo entry filter. PAT-LIST is a list of pattern elements.
Each element may be t, nil, or a string."
(unless (memq nil pat-list)
@@ -300,9 +292,9 @@ Each element may be t, nil, or a string."
;; Work with regular expression patterns rather than strings
-(defun hyrolo-r-not (&rest pat-list)
+(defun hyrolo-r-not (start end &rest pat-list)
"Logical <not> rolo entry filter. PAT-LIST is a list of pattern elements.
-Each element may be t, nil, or a string."
+Each element may be t, nil, or a regular expression."
(let ((pat))
(while (and pat-list
(or (null (setq pat (car pat-list)))
@@ -312,9 +304,9 @@ Each element may be t, nil, or a string."
(setq pat-list (cdr pat-list)))
(not pat-list)))
-(defun hyrolo-r-or (&rest pat-list)
+(defun hyrolo-r-or (start end &rest pat-list)
"Logical <or> rolo entry filter. PAT-LIST is a list of pattern elements.
-Each element may be t, nil, or a string."
+Each element may be t, nil, or a regular expression."
(if (memq t pat-list)
t
(let ((pat))
@@ -326,9 +318,9 @@ Each element may be t, nil, or a string."
(setq pat-list (cdr pat-list)))
(if pat-list t nil))))
-(defun hyrolo-r-xor (&rest pat-list)
+(defun hyrolo-r-xor (start end &rest pat-list)
"Logical <xor> rolo entry filter. PAT-LIST is a list of pattern elements.
-Each element may be t, nil, or a string."
+Each element may be t, nil, or a regular expression."
(let ((pat)
(matches 0))
(while (and pat-list
@@ -342,9 +334,9 @@ Each element may be t, nil, or a string."
(setq pat-list (cdr pat-list)))
(= matches 1)))
-(defun hyrolo-r-and (&rest pat-list)
+(defun hyrolo-r-and (start end &rest pat-list)
"Logical <and> rolo entry filter. PAT-LIST is a list of pattern elements.
-Each element may be t, nil, or a string."
+Each element may be t, nil, or a regular expression."
(unless (memq nil pat-list)
(let ((pat))
(while (and pat-list
diff --git a/hyrolo.el b/hyrolo.el
index 9a079a7..e9edc6f 100644
--- a/hyrolo.el
+++ b/hyrolo.el
@@ -105,14 +105,14 @@ executable must be found as well (for Oauth security)."
;; If no gpg encryption executable, Oauth login to Google will fail.
(or (executable-find "gpg2") (executable-find "gpg"))))
-'("~/.rolo.otl" "~/.rolo.org" "c:/_rolo.otl")
+;; '("~/.rolo.otl" "~/.rolo.org")
;;;###autoload
(defun hyrolo-initialize-file-list ()
"Initialize the list of files used for HyRolo search."
(interactive)
(let* ((gcontacts (when (hyrolo-google-contacts-p)
google-contacts-buffer-name))
- (ms "c:/_rolo.otl")
+ (ms "~/.rolo.otl")
(posix "~/.rolo.otl")
(list (delq nil (if (and (boundp 'bbdb-file) (stringp bbdb-file))
(if hyperb:microsoft-os-p
@@ -585,14 +585,17 @@ Return t if entry is killed, nil otherwise."
(interactive)
(hyrolo-verify)
(let ((start (point))
- (case-fold-search t))
- (if (looking-at hyrolo-match-regexp)
- (goto-char (match-end 0)))
- (if (re-search-forward hyrolo-match-regexp nil t)
+ (case-fold-search t)
+ (prior-regexp-search (stringp hyrolo-match-regexp)))
+ (when (and prior-regexp-search (looking-at hyrolo-match-regexp))
+ (goto-char (match-end 0)))
+ (if (and prior-regexp-search (re-search-forward hyrolo-match-regexp nil
t))
(goto-char (match-beginning 0))
(goto-char start)
- (error
- "(hyrolo-next-match): No following matches for \"%s\""
hyrolo-match-regexp))))
+ (if prior-regexp-search
+ (error
+ "(hyrolo-next-match): No following matches for \"%s\""
hyrolo-match-regexp)
+ (error "(hyrolo-next-match): No prior regular expression search to
match")))))
(defun hyrolo-overview (levels-to-show)
"Show the first line of all levels of rolo matches.
@@ -638,7 +641,7 @@ XEmacs only."
(defun hyrolo-rename (old-file new-file)
"Prompt user to rename OLD-FILE to NEW-FILE."
(interactive (if hyperb:microsoft-os-p
- '("c:/_rolodex.otl" "c:/_rolo.otl")
+ '("c:/_rolo.otl" "~/.rolo.otl")
'("~/.rolodex.otl" "~/.rolo.otl")))
(if (and (equal (car hyrolo-file-list) new-file)
(file-readable-p old-file)
@@ -653,12 +656,12 @@ XEmacs only."
nil))))
(progn (rename-file old-file new-file 1)
;; Also rename backup file if it exists.
- (if (file-readable-p (concat old-file "~"))
- (rename-file (concat old-file "~") (concat new-file "~") 1))
- (if (get-file-buffer old-file)
- (with-current-buffer (get-file-buffer old-file)
- (rename-buffer (file-name-nondirectory new-file))
- (setq buffer-file-name (expand-file-name new-file))))
+ (when (file-readable-p (concat old-file "~"))
+ (rename-file (concat old-file "~") (concat new-file "~") 1))
+ (when (get-file-buffer old-file)
+ (with-current-buffer (get-file-buffer old-file)
+ (rename-buffer (file-name-nondirectory new-file))
+ (setq buffer-file-name (expand-file-name new-file))))
(message "(HyRolo): Your personal rolo file is now: \"%s\"."
new-file))))
@@ -686,18 +689,18 @@ Return list of number of groupings at each entry level."
(car hyrolo-file-list)))))
(mapcar #'list hyrolo-file-list)))
(if (string-equal file "") default file))))
- (if (or (not hyrolo-file) (equal hyrolo-file ""))
- (setq hyrolo-file (car hyrolo-file-list)))
- (if (not (and (stringp hyrolo-file) (file-readable-p hyrolo-file)))
- (error "(hyrolo-sort): Invalid or unreadable file: %s" hyrolo-file))
+ (when (or (not hyrolo-file) (equal hyrolo-file ""))
+ (setq hyrolo-file (car hyrolo-file-list)))
+ (unless (and (stringp hyrolo-file) (file-readable-p hyrolo-file))
+ (error "(hyrolo-sort): Invalid or unreadable file: %s" hyrolo-file))
(let ((level-regexp (regexp-quote "**************"))
(entries-per-level-list)
(n))
(while (not (equal level-regexp ""))
(setq n (hyrolo-sort-level hyrolo-file level-regexp))
- (if (or (/= n 0) entries-per-level-list)
- (setq entries-per-level-list
- (append (list n) entries-per-level-list)))
+ (when (or (/= n 0) entries-per-level-list)
+ (setq entries-per-level-list
+ (append (list n) entries-per-level-list)))
(setq level-regexp (substring level-regexp 0 (- (length level-regexp)
2))))
entries-per-level-list))
@@ -722,7 +725,8 @@ of groupings sorted."
"Move forward by optional ARG lines (default = 1), ignoring currently
invisible newlines only.
If ARG is negative, move backward -ARG lines.
If ARG is zero, move to the beginning of the current line."
- (if (null arg) (setq arg 1))
+ (unless arg
+ (setq arg 1))
(forward-visible-line arg))
;; Derived from `sort-lines' in "sort.el" since through at least Emacs 25.0
@@ -739,9 +743,9 @@ the sort order."
(save-restriction
(narrow-to-region beg end)
(goto-char (point-min))
- (let ;; To make `end-of-line' and etc. to ignore fields.
- ((inhibit-field-text-motion t))
- (sort-subr reverse 'hyrolo-forward-visible-line
'end-of-visible-line)))))
+ ;; To make `end-of-line', etc. ignore fields
+ (let ((inhibit-field-text-motion t))
+ (sort-subr reverse #'hyrolo-forward-visible-line
#'end-of-visible-line)))))
;;;###autoload
(defun hyrolo-toggle-datestamps (&optional arg)
@@ -765,10 +769,10 @@ Useful when bound to a mouse key."
(interactive)
(if (hyrolo-narrowed-p)
(widen)
- (if (or (looking-at hyrolo-entry-regexp)
- (re-search-backward hyrolo-entry-regexp nil t))
- (progn (forward-char)
- (narrow-to-region (1- (point)) (hyrolo-display-to-entry-end)))))
+ (when (or (looking-at hyrolo-entry-regexp)
+ (re-search-backward hyrolo-entry-regexp nil t))
+ (forward-char)
+ (narrow-to-region (1- (point)) (hyrolo-display-to-entry-end))))
(hyrolo-shrink-window)
(goto-char (point-min)))
@@ -797,10 +801,10 @@ hyrolo-file-list."
(let ((total-matches (hyrolo-grep (format "\\b%s\\b" (regexp-quote string))
max-matches
hyrolo-file count-only no-display)))
- (if (called-interactively-p 'interactive)
- (message "%s matching entr%s found in the rolo."
- (if (= total-matches 0) "No" total-matches)
- (if (= total-matches 1) "y" "ies")))
+ (when (called-interactively-p 'interactive)
+ (message "%s matching entr%s found in the rolo."
+ (if (= total-matches 0) "No" total-matches)
+ (if (= total-matches 1) "y" "ies")))
total-matches))
;;;###autoload
@@ -1156,71 +1160,70 @@ beginning of a line (^); an example, might be
(regexp-quote \"**\") to match
level two.
Return number of groupings matched."
(let ((actual-buf))
- (if (and (or (null max-groupings) (< 0 max-groupings))
- (or (setq actual-buf (hyrolo-buffer-exists-p hyrolo-file-or-buf))
- (if (file-exists-p hyrolo-file-or-buf)
- (progn (setq actual-buf (find-file-noselect
hyrolo-file-or-buf t))
- t))))
- (progn
- (set-buffer actual-buf)
- (let ((num-found 0)
- (exact-level-regexp (concat "^\\(" level-regexp "\\)[ \t\n\r]"))
- (outline-regexp hyrolo-entry-regexp)
- (buffer-read-only)
- (level-len))
- (goto-char (point-min))
- ;; Pass buffer header if it exists
- (if (re-search-forward hyrolo-hdr-regexp nil t 2)
- (forward-line))
- (while (and (or (null max-groupings) (< num-found max-groupings))
- (re-search-forward exact-level-regexp nil t))
- (setq num-found (1+ num-found))
- (let* ((opoint (prog1 (point) (beginning-of-line)))
- (grouping-start (point))
- (start grouping-start)
- (level-len (or level-len (- (1- opoint) start)))
- (next-level-len)
- (next-entry-exists)
- (grouping-end)
- (no-subtree))
- (while (and (progn
- (if (setq next-entry-exists
- (re-search-forward
- hyrolo-entry-regexp nil t 2))
- (setq next-level-len
- (- (point)
- (progn (beginning-of-line)
- (point)))
- grouping-end
- (< next-level-len level-len)
- no-subtree
- (<= next-level-len level-len))
- (setq grouping-end t no-subtree t)
- (goto-char (point-max)))
- (let ((end (point)))
- (goto-char start)
- (outline-hide-subtree) ; and hide multiple
entry lines
- ;; Move to start of next entry at equal
- ;; or higher level.
- (setq start
- (if no-subtree
- end
- (if (re-search-forward
- hyrolo-entry-regexp nil t)
- (progn (beginning-of-line) (point))
- (point-max))))
- ;; Remember last expression in `progn'
- ;; must always return non-nil.
- (goto-char start)))
- (not grouping-end)))
- (let ((end (point)))
- (goto-char grouping-start)
- (funcall func grouping-start end)
- (goto-char end))))
- (outline-show-all)
- (hyrolo-kill-buffer actual-buf)
- num-found))
- 0)))
+ (if (not (and (or (null max-groupings) (< 0 max-groupings))
+ (or (setq actual-buf (hyrolo-buffer-exists-p
hyrolo-file-or-buf))
+ (when (file-exists-p hyrolo-file-or-buf)
+ (setq actual-buf (find-file-noselect hyrolo-file-or-buf
t))
+ t))))
+ 0
+ (set-buffer actual-buf)
+ (let ((num-found 0)
+ (exact-level-regexp (concat "^\\(" level-regexp "\\)[ \t\n\r]"))
+ (outline-regexp hyrolo-entry-regexp)
+ (buffer-read-only)
+ (level-len))
+ (goto-char (point-min))
+ ;; Pass buffer header if it exists
+ (if (re-search-forward hyrolo-hdr-regexp nil t 2)
+ (forward-line))
+ (while (and (or (null max-groupings) (< num-found max-groupings))
+ (re-search-forward exact-level-regexp nil t))
+ (setq num-found (1+ num-found))
+ (let* ((opoint (prog1 (point) (beginning-of-line)))
+ (grouping-start (point))
+ (start grouping-start)
+ (level-len (or level-len (- (1- opoint) start)))
+ (next-level-len)
+ (next-entry-exists)
+ (grouping-end)
+ (no-subtree))
+ (while (and (progn
+ (if (setq next-entry-exists
+ (re-search-forward
+ hyrolo-entry-regexp nil t 2))
+ (setq next-level-len
+ (- (point)
+ (progn (beginning-of-line)
+ (point)))
+ grouping-end
+ (< next-level-len level-len)
+ no-subtree
+ (<= next-level-len level-len))
+ (setq grouping-end t no-subtree t)
+ (goto-char (point-max)))
+ (let ((end (point)))
+ (goto-char start)
+ (outline-hide-subtree) ; and hide multiple entry
lines
+ ;; Move to start of next entry at equal
+ ;; or higher level.
+ (setq start
+ (if no-subtree
+ end
+ (if (re-search-forward
+ hyrolo-entry-regexp nil t)
+ (progn (beginning-of-line) (point))
+ (point-max))))
+ ;; Remember last expression in `progn'
+ ;; must always return non-nil.
+ (goto-char start)))
+ (not grouping-end)))
+ (let ((end (point)))
+ (goto-char grouping-start)
+ (funcall func grouping-start end)
+ (goto-char end))))
+ (outline-show-all)
+ (hyrolo-kill-buffer actual-buf)
+ num-found))))
;;; ************************************************************************
;;; Private functions