branch: master
commit da3faf59ec60fd3b23dcf985757defa5ea0239a4
Author: Basil L. Contovounesios <[email protected]>
Commit: Oleh Krehel <[email protected]>
Minor major-mode touch-ups
* counsel.el (counsel-at-git-issue-p, counsel-org-goto,
counsel-org-goto-all, counsel-list-buffers-with-mode):
* swiper.el (swiper-all-buffer-p): Simplify and optimise logic.
(swiper-font-lock-ensure-p): Fix indentation.
Fixes #1334
---
counsel.el | 40 ++++++++++++++--------------------------
swiper.el | 14 +++++++-------
2 files changed, 21 insertions(+), 33 deletions(-)
diff --git a/counsel.el b/counsel.el
index 125788e..d1f4895 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1762,11 +1762,9 @@ further, make the remote prefix editable"
(defun counsel-at-git-issue-p ()
"When point is at an issue in a Git-versioned file, return the issue string."
(and (looking-at "#[0-9]+")
- (or
- (eq (vc-backend (buffer-file-name)) 'Git)
- (or
- (memq major-mode '(magit-commit-mode))
- (bound-and-true-p magit-commit-mode)))
+ (or (eq (vc-backend buffer-file-name) 'Git)
+ (eq major-mode 'magit-commit-mode)
+ (bound-and-true-p magit-commit-mode))
(match-string-no-properties 0)))
(defun counsel-github-url-p ()
@@ -2759,12 +2757,10 @@ to custom."
(defun counsel-org-goto ()
"Go to a different location in the current file."
(interactive)
- (let ((entries (counsel-org-goto--get-headlines)))
- (ivy-read "Goto: "
- entries
- :history 'counsel-org-goto-history
- :action 'counsel-org-goto-action
- :caller 'counsel-org-goto)))
+ (ivy-read "Goto: " (counsel-org-goto--get-headlines)
+ :history 'counsel-org-goto-history
+ :action 'counsel-org-goto-action
+ :caller 'counsel-org-goto))
;;;###autoload
(defun counsel-org-goto-all ()
@@ -2774,11 +2770,8 @@ to custom."
(dolist (b (buffer-list))
(with-current-buffer b
(when (derived-mode-p 'org-mode)
- (if entries
- (nconc entries (counsel-org-goto--get-headlines))
- (setq entries (counsel-org-goto--get-headlines))))))
- (ivy-read "Goto: "
- entries
+ (setq entries (nconc entries (counsel-org-goto--get-headlines))))))
+ (ivy-read "Goto: " entries
:history 'counsel-org-goto-history
:action 'counsel-org-goto-action
:caller 'counsel-org-goto-all)))
@@ -4230,16 +4223,11 @@ Remaps built-in functions to counsel replacements.")
:type 'boolean)
(defun counsel-list-buffers-with-mode (mode)
- "List all buffers with `major-mode' MODE.
-
-MODE is a symbol."
- (save-current-buffer
- (let (bufs)
- (dolist (buf (buffer-list))
- (set-buffer buf)
- (and (equal major-mode mode)
- (push (buffer-name buf) bufs)))
- (nreverse bufs))))
+ "Return names of buffers with `major-mode' `eq' to MODE."
+ (let (bufs)
+ (dolist (buf (buffer-list) (nreverse bufs))
+ (when (eq (buffer-local-value 'major-mode buf) mode)
+ (push (buffer-name buf) bufs)))))
;;;###autoload
(defun counsel-switch-to-shell-buffer ()
diff --git a/swiper.el b/swiper.el
index 2f514ef..80e5b64 100644
--- a/swiper.el
+++ b/swiper.el
@@ -295,8 +295,8 @@
(defun swiper-font-lock-ensure-p ()
"Return non-nil if we should `font-lock-ensure'."
(or (derived-mode-p 'magit-mode)
- (bound-and-true-p magit-blame-mode)
- (memq major-mode swiper-font-lock-exclude)))
+ (bound-and-true-p magit-blame-mode)
+ (memq major-mode swiper-font-lock-exclude)))
(defun swiper-font-lock-ensure ()
"Ensure the entired buffer is highlighted."
@@ -817,19 +817,19 @@ otherwise continue prompting for buffers."
(defun swiper-all-buffer-p (buffer)
"Return non-nil if BUFFER should be considered by `swiper-all'."
- (let ((major-mode (with-current-buffer buffer major-mode)))
+ (let ((mode (buffer-local-value 'major-mode (get-buffer buffer))))
(cond
;; Ignore TAGS buffers, they tend to add duplicate results.
- ((eq major-mode #'tags-table-mode) nil)
+ ((eq mode #'tags-table-mode) nil)
;; Always consider dired buffers, even though they're not backed
;; by a file.
- ((eq major-mode #'dired-mode) t)
+ ((eq mode #'dired-mode) t)
;; Always consider stash buffers too, as they may have
;; interesting content not present in any buffers. We don't #'
;; quote to satisfy the byte-compiler.
- ((eq major-mode 'magit-stash-mode) t)
+ ((eq mode 'magit-stash-mode) t)
;; Email buffers have no file, but are useful to search
- ((eq major-mode 'gnus-article-mode) t)
+ ((eq mode 'gnus-article-mode) t)
;; Otherwise, only consider the file if it's backed by a file.
(t (buffer-file-name buffer)))))