branch: externals/ivy
commit 79d0497eae1f1abca166fa1e498c71a14af9fa71
Author: Basil L. Contovounesios <[email protected]>
Commit: Basil L. Contovounesios <[email protected]>
Simplify some cl-lib uses
This after realizing that cl-find currently traverses the sequence
twice, which makes it doubly unsuitable as a boolean predicate.
* ivy.el (ivy-default-view-name, ivy--switch-buffer-matcher)
(ivy--select-occur-buffer):
* swiper.el (swiper-match-usable-p):
* counsel.el (counsel--file-name-filter)
(counsel-buffer-or-recentf-candidates, counsel--package-candidates)
(counsel-linux-apps-list): Simplify.
(counsel-bookmarked-directory--candidates): Ditto. Rename...
(counsel--bookmarked-dirs): ...to this. All uses updated.
(counsel-bookmarked-directory): Refill docstring.
(counsel-file-stale-p): Also return non-nil for nonexistent file, in
a single filesystem access.
(counsel--locate-updatedb): Update accordingly.
---
counsel.el | 73 ++++++++++++++++++++++++++++++--------------------------------
ivy.el | 72 +++++++++++++++++++++++++++----------------------------------
swiper.el | 7 +++---
3 files changed, 70 insertions(+), 82 deletions(-)
diff --git a/counsel.el b/counsel.el
index 9aa7f1c535..828f0b8c99 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2246,10 +2246,10 @@ If USE-IGNORE is non-nil, try to generate a command
that respects
(let ((regex ivy--old-re))
(if (= 0 (length regex))
"cat"
- (let ((filter-cmd (cl-find-if
- (lambda (x)
+ (let ((filter-cmd (cl-assoc-if
+ (lambda (cmd)
(executable-find
- (car (split-string (car x)))))
+ (car (split-string cmd))))
counsel-file-name-filter-alist))
cmd)
(when (and use-ignore ivy-use-ignore
@@ -2561,10 +2561,8 @@ This function uses the `dom' library from Emacs 25.1 or
later."
"Return candidates for `counsel-buffer-or-recentf'."
(recentf-mode)
(let ((buffers (delq nil (mapcar #'buffer-file-name (buffer-list)))))
- (nconc
- buffers
- (cl-remove-if (lambda (f) (member f buffers))
- (counsel-recentf-candidates)))))
+ (nconc buffers (cl-set-difference (counsel-recentf-candidates)
+ buffers :test #'equal))))
;;;###autoload
(defun counsel-buffer-or-recentf ()
@@ -2647,24 +2645,24 @@ By default `counsel-bookmark' opens a dired buffer for
directories."
;;;; `counsel-bookmarked-directory'
-(defun counsel-bookmarked-directory--candidates ()
- "Get a list of bookmarked directories sorted by file path."
+(defun counsel--bookmarked-dirs ()
+ "Return a list of bookmarked directories sorted by file name."
(bookmark-maybe-load-default-file)
- (sort (cl-delete-if-not
- #'ivy--dirname-p
- (delq nil (mapcar #'bookmark-get-filename bookmark-alist)))
+ (sort (cl-mapcan (lambda (bm)
+ (let ((dir (bookmark-get-filename bm)))
+ (and dir (ivy--dirname-p dir) (list dir))))
+ bookmark-alist)
#'string<))
;;;###autoload
(defun counsel-bookmarked-directory ()
"Ivy interface for bookmarked directories.
-With a prefix argument, this command creates a new bookmark which points to the
-current value of `default-directory'."
+With a prefix argument, this command creates a new bookmark which points
+to the current value of `default-directory'."
(interactive)
(require 'bookmark)
- (ivy-read "Bookmarked directory: "
- (counsel-bookmarked-directory--candidates)
+ (ivy-read "Bookmarked directory: " (counsel--bookmarked-dirs)
:caller 'counsel-bookmarked-directory
:action #'dired))
@@ -2828,17 +2826,19 @@ library, which see."
"Location where to put the locatedb in case your home folder is encrypted."
:type 'file)
-(defun counsel-file-stale-p (fname seconds)
- "Return non-nil if FNAME was modified more than SECONDS ago."
- (> (float-time (time-since (nth 5 (file-attributes fname))))
- seconds))
+(defun counsel-file-stale-p (file seconds)
+ "Return non-nil if FILE was modified more than SECONDS ago.
+Also return non-nil if FILE does not exist."
+ (let ((mtime (nth 5 (file-attributes file))))
+ (or (not mtime)
+ (> (float-time (time-since mtime))
+ seconds))))
(defun counsel--locate-updatedb ()
(when (file-exists-p "~/.Private")
(let ((db-fname (expand-file-name counsel-locate-db-path)))
(setenv "LOCATE_PATH" db-fname)
- (when (or (not (file-exists-p db-fname))
- (counsel-file-stale-p db-fname 60))
+ (when (counsel-file-stale-p db-fname 60)
(message "Updating %s..." db-fname)
(counsel--command
"updatedb" "-l" "0" "-o" db-fname "-U" (expand-file-name "~"))))))
@@ -4468,16 +4468,14 @@ When ARG is non-nil, display all active evil registers."
"Return completion alist for `counsel-package'."
(unless package--initialized
(package-initialize t))
- (if (or (not package-archive-contents)
- (cl-find-if (lambda (package-archive)
- (let ((fname
- (format
- "%s/archives/%s/archive-contents"
- package-user-dir (car package-archive))))
- (or (not (file-exists-p fname))
- (counsel-file-stale-p fname (* 4 60 60)))))
- package-archives))
- (package-refresh-contents))
+ (when (or (null package-archive-contents)
+ (cl-some (lambda (archive)
+ (let* ((fname (format "archives/%s/archive-contents"
+ (car archive)))
+ (fname (expand-file-name fname
package-user-dir)))
+ (counsel-file-stale-p fname (* 4 60 60))))
+ package-archives))
+ (package-refresh-contents))
(sort (mapcar (lambda (entry)
(cons (let ((pkg (car entry)))
(concat (if (package-installed-p pkg) "-" "+")
@@ -6491,12 +6489,11 @@ Any desktop entries that fail to parse are recorded in
(eq counsel-linux-app-format-function
counsel--linux-apps-cache-format-function)
(equal new-files counsel--linux-apps-cached-files)
- (null (cl-find-if
- (lambda (file)
- (time-less-p
- counsel--linux-apps-cache-timestamp
- (nth 5 (file-attributes file))))
- new-files)))
+ (cl-notany (lambda (file)
+ (time-less-p
+ counsel--linux-apps-cache-timestamp
+ (nth 5 (file-attributes file))))
+ new-files))
(setq counsel--linux-apps-cache (counsel-linux-apps-parse
new-desktop-alist))
(setq counsel--linux-apps-cache-format-function
counsel-linux-app-format-function)
(setq counsel--linux-apps-cache-timestamp (current-time))
diff --git a/ivy.el b/ivy.el
index b614dcb499..7dff3efc6a 100644
--- a/ivy.el
+++ b/ivy.el
@@ -4462,32 +4462,26 @@ TREE can be nested multiple times to have multiple
window splits.")
(defun ivy-default-view-name ()
"Return default name for new view."
- (let* ((default-view-name
- (concat "{} "
- (mapconcat #'identity
- (sort
- (mapcar (lambda (w)
- (let* ((b (window-buffer w))
- (f (buffer-file-name b)))
- (if f
- (file-name-nondirectory f)
- (buffer-name b))))
- (window-list))
- #'string-lessp)
- " ")))
+ (let* ((wins (mapcar (lambda (w)
+ (let* ((b (window-buffer w))
+ (f (buffer-file-name b)))
+ (if f
+ (file-name-nondirectory f)
+ (buffer-name b))))
+ (window-list)))
+ (default-view-name
+ (string-join (cons "{}" (sort wins #'string-lessp))
+ " "))
(view-name-re (concat "\\`"
(regexp-quote default-view-name)
- " \\([0-9]+\\)"))
- old-view)
- (cond ((setq old-view
- (cl-find-if
- (lambda (x)
- (string-match view-name-re (car x)))
- ivy-views))
- (format "%s %d"
- default-view-name
- (1+ (string-to-number
- (match-string 1 (car old-view))))))
+ " \\([0-9]+\\)")))
+ (cond ((let ((num (cl-some (lambda (view)
+ (let ((name (car view)))
+ (and (string-match view-name-re name)
+ (string-to-number
+ (match-string 1 name)))))
+ ivy-views)))
+ (and num (format "%s %d" default-view-name (1+ num)))))
((assoc default-view-name ivy-views)
(concat default-view-name " 1"))
(t
@@ -4756,21 +4750,20 @@ Skip buffers that match `ivy-ignore-buffers'."
(and b (string-match-p
regexp (buffer-local-value 'default-directory b))))))
(copy-sequence candidates)))
- (let ((res (ivy--re-filter regexp candidates)))
- (if (or (null ivy-use-ignore)
- (null ivy-ignore-buffers))
- res
- (or (cl-remove-if
- (lambda (buf)
- (cl-find-if
- (lambda (f-or-r)
- (if (functionp f-or-r)
- (funcall f-or-r buf)
- (string-match-p f-or-r buf)))
- ivy-ignore-buffers))
+ (let ((res (ivy--re-filter regexp candidates))
+ (policy ivy-use-ignore)
+ (ignores ivy-ignore-buffers))
+ (cond ((null (and policy ignores))
res)
- (and (eq ivy-use-ignore t)
- res))))))
+ ((cl-remove-if (lambda (buf)
+ (cl-some (lambda (f-or-r)
+ (if (stringp f-or-r)
+ (string-match-p f-or-r buf)
+ (funcall f-or-r buf)))
+ ignores))
+ res))
+ ((eq policy t)
+ res)))))
(defun ivy-append-face (str face)
"Append to STR the property FACE."
@@ -5144,8 +5137,7 @@ buffer would modify `ivy-last'.")
(defun ivy--select-occur-buffer ()
(let* ((ob (ivy--find-occur-buffer))
- (ow (cl-find-if (lambda (w) (equal ob (window-buffer w)))
- (window-list))))
+ (ow (get-buffer-window ob)))
(if ow
(select-window ow)
(pop-to-buffer ob))))
diff --git a/swiper.el b/swiper.el
index c35180e033..eefb695b6c 100644
--- a/swiper.el
+++ b/swiper.el
@@ -1394,10 +1394,9 @@ See `ivy-format-functions-alist' for further
information."
(defun swiper-match-usable-p ()
(or search-invisible
- (not (cl-find-if
- (lambda (ov)
- (invisible-p (overlay-get ov 'invisible)))
- (overlays-at (point))))))
+ (cl-notany (lambda (ov)
+ (invisible-p (overlay-get ov 'invisible)))
+ (overlays-at (point)))))
(defvar swiper--isearch-backward nil
"Non-nil when performing `swiper-isearch-backward'.")