branch: externals/counsel
commit c77594c51d5254bff03f8cd1258fb865a8bdbcac
Merge: eaf7cbb152 6227843101
Author: Basil L. Contovounesios <ba...@contovou.net>
Commit: Basil L. Contovounesios <ba...@contovou.net>

    Merge branch 'master' into externals/counsel
---
 .mailmap   |  1 +
 counsel.el | 76 +++++++++++++++++++++++++++++++++++++-------------------------
 2 files changed, 46 insertions(+), 31 deletions(-)

diff --git a/.mailmap b/.mailmap
index fa38b3f201..eb78d6ffb0 100644
--- a/.mailmap
+++ b/.mailmap
@@ -19,6 +19,7 @@
 <ricouillet...@gmail.com> <eric.da...@u-cergy.fr>
 <syo...@gmail.com> <shohei.yosh...@dena.com>
 <ywwr...@gmail.com> <58066925+ywwr...@users.noreply.github.com>
+Christopher Floess <chris.flo...@mailbox.org>
 Daanturo <daant...@gmail.com> <dantle....@gmail.com>
 Diego A. Mundo <diegoamu...@gmail.com>
 Earl Hyatt <oka...@protonmail.com> <ej...@protonmail.com>
diff --git a/counsel.el b/counsel.el
index 1698346542..81db4e6b45 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1,6 +1,6 @@
 ;;; counsel.el --- Various completion functions using Ivy -*- lexical-binding: 
t -*-
 
-;; Copyright (C) 2015-2024 Free Software Foundation, Inc.
+;; Copyright (C) 2015-2025 Free Software Foundation, Inc.
 
 ;; Author: Oleh Krehel <ohwoeo...@gmail.com>
 ;; Maintainer: Basil L. Contovounesios <ba...@contovou.net>
@@ -1429,23 +1429,36 @@ This function should set `ivy--old-re'."
   "Grep in the current Git repository for STRING."
   (or
    (ivy-more-chars)
-   (progn
-     (counsel--async-command
-      (concat
-       (funcall counsel-git-grep-cmd-function string)
-       (if (ivy--case-fold-p string) " -i" "")))
-     nil)))
+   (ignore
+    (counsel--async-command
+     (concat
+      (funcall counsel-git-grep-cmd-function string)
+      (and (ivy--case-fold-p string) " -i"))))))
 
 (defun counsel-git-grep-action (x)
   "Go to occurrence X in current Git repository."
-  (when (string-match "\\`\\(.*?\\):\\([0-9]+\\):\\(.*\\)\\'" x)
-    (let ((file-name (match-string-no-properties 1 x))
-          (line-number (match-string-no-properties 2 x)))
-      (find-file (expand-file-name
-                  file-name
-                  (ivy-state-directory ivy-last)))
+  (counsel--git-grep-visit x))
+
+(defun counsel-git-grep-action-other-window (x)
+  "Go to occurrence X in current Git repository in another window."
+  (counsel--git-grep-visit x t))
+
+(defun counsel--git-grep-file-and-line (x)
+  "Extract file name and line number from `counsel-git-grep' line X.
+Return a pair (FILE . LINE) on success; nil otherwise."
+  (and (string-match "\\`\\(.*?\\):\\([0-9]+\\):\\(.*\\)\\'" x)
+       (cons (match-string-no-properties 1 x)
+             (string-to-number (match-string-no-properties 2 x)))))
+
+(defun counsel--git-grep-visit (cand &optional other-window)
+  "Visit `counsel-git-grep' CAND, optionally in OTHER-WINDOW."
+  (let ((file-and-line (counsel--git-grep-file-and-line cand)))
+    (when file-and-line
+      (funcall (if other-window #'find-file-other-window #'find-file)
+               (expand-file-name (car file-and-line)
+                                 (ivy-state-directory ivy-last)))
       (goto-char (point-min))
-      (forward-line (1- (string-to-number line-number)))
+      (forward-line (1- (cdr file-and-line)))
       (when (re-search-forward (ivy--regex ivy-text t) (line-end-position) t)
         (when swiper-goto-start-of-match
           (goto-char (match-beginning 0))))
@@ -1455,6 +1468,10 @@ This function should set `ivy--old-re'."
         (swiper--cleanup)
         (swiper--add-overlays (ivy--regex ivy-text))))))
 
+(ivy-set-actions
+ 'counsel-git-grep
+ '(("j" counsel-git-grep-action-other-window "other window")))
+
 (defun counsel-git-grep-transformer (str)
   "Highlight file and line number in STR."
   (when (string-match "\\`\\([^:]+\\):\\([^:]+\\):" str)
@@ -2754,7 +2771,7 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
 (defvar counsel--fzf-dir nil
   "Store the base fzf directory.")
 
-(defvar counsel-fzf-dir-function 'counsel-fzf-dir-function-projectile
+(defvar counsel-fzf-dir-function #'counsel-fzf-dir-function-projectile
   "Function that returns a directory for fzf to use.")
 
 (defun counsel-fzf-dir-function-projectile ()
@@ -6856,22 +6873,19 @@ Additional actions:
 
 The alist element is cons of minor mode string with its lighter
 and minor mode symbol."
-  (delq nil
-        (mapcar
-         (lambda (mode)
-           (when (and (boundp mode) (commandp mode))
-             (let ((lighter (cdr (assq mode minor-mode-alist))))
-               (cons (concat
-                      (if (symbol-value mode) "-" "+")
-                      (symbol-name mode)
-                      (propertize
-                       (if lighter
-                           (format " \"%s\""
-                                   (format-mode-line (cons t lighter)))
-                         "")
-                       'face font-lock-string-face))
-                     mode))))
-         minor-mode-list)))
+  (cl-mapcan
+   (let ((suffix (propertize " \"%s\"" 'face 'font-lock-string-face)))
+     (lambda (mode)
+       (when (and (boundp mode) (commandp mode))
+         (let ((lighter (cdr (assq mode minor-mode-alist))))
+           (list (cons (concat
+                        (if (symbol-value mode) "-" "+")
+                        (symbol-name mode)
+                        (and lighter
+                             (format suffix
+                                     (format-mode-line (cons t lighter)))))
+                       mode))))))
+   minor-mode-list))
 
 ;;;###autoload
 (defun counsel-minor ()

Reply via email to