[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/detached 3e54ebb5cb 3/5: Create support function for gr
From: |
ELPA Syncer |
Subject: |
[elpa] externals/detached 3e54ebb5cb 3/5: Create support function for grepping sessions |
Date: |
Fri, 14 Oct 2022 14:57:31 -0400 (EDT) |
branch: externals/detached
commit 3e54ebb5cb7a26592d3cd31d10b761d800c83a4b
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>
Create support function for grepping sessions
---
detached-list.el | 88 +++++++++++++++++++++++++++++---------------------------
1 file changed, 46 insertions(+), 42 deletions(-)
diff --git a/detached-list.el b/detached-list.el
index 369fd1f5ea..ba3801ac8a 100644
--- a/detached-list.el
+++ b/detached-list.el
@@ -255,48 +255,7 @@ Optionally SUPPRESS-OUTPUT."
(detached-list-narrow-sessions
`((,(concat "Output: " regexp) .
,(lambda (sessions)
- (let* ((sessions-and-directories
- (thread-last sessions
- (seq-group-by #'detached--session-directory)
- (seq-filter (lambda (it)
- ;; Filter out only accessible
directories
- (or (not (file-remote-p (car
it)))
- (file-remote-p (car it) nil
t))))))
- (session-ids
- (thread-last sessions-and-directories
- (seq-map
- (lambda (it)
- (pcase-let* ((`(,session-directory .
,sessions) it)
- (default-directory
session-directory)
- (includes
- (seq-map (lambda (session)
- (format
"--include=%s"
-
(file-name-nondirectory
-
(detached--session-file
- session
- 'log))))
- sessions))
- (grep-command
- (string-join
`(,detached-grep-program
-
"--files-with-matches"
- ,@includes
- "--no-messages"
- "--ignore-case"
- "--recursive"
- ,(format
"\"%s\"" regexp))
- " ")))
- (split-string
- (with-connection-local-variables
- (with-temp-buffer
- (process-file-shell-command
grep-command nil t)
- (buffer-string)))
- "\n" t))))
- (flatten-tree)
- (seq-remove #'null)
- (seq-map #'file-name-sans-extension))))
- (seq-filter (lambda (it)
- (member (symbol-name (detached--session-id it))
session-ids))
- sessions))))
+ (detached--grep-sesssions-output sessions regexp)))
,@detached-list--filters))))
(defun detached-list-narrow-regexp (regexp)
@@ -652,6 +611,51 @@ If prefix-argument is provided unmark instead of mark."
"Return session when in `detached-list-mode'."
(tabulated-list-get-id))
+(defun detached--grep-sesssions-output (sessions regexp)
+ "Return a narrowed list with SESSIONS containing REGEXP."
+ (let* ((sessions-and-directories
+ (thread-last sessions
+ (seq-group-by #'detached--session-directory)
+ (seq-filter (lambda (it)
+ ;; Filter out only accessible directories
+ (or (not (file-remote-p (car it)))
+ (file-remote-p (car it) nil t))))))
+ (session-ids
+ (thread-last sessions-and-directories
+ (seq-map
+ (lambda (it)
+ (pcase-let* ((`(,session-directory . ,sessions) it)
+ (default-directory session-directory)
+ (includes
+ (seq-map (lambda (session)
+ (format "--include=%s"
+
(file-name-nondirectory
+
(detached--session-file
+ session
+ 'log))))
+ sessions))
+ (grep-command
+ (string-join `(,detached-grep-program
+ "--files-with-matches"
+ ,@includes
+ "--no-messages"
+ "--ignore-case"
+ "--recursive"
+ ,(format "\"%s\""
regexp))
+ " ")))
+ (split-string
+ (with-connection-local-variables
+ (with-temp-buffer
+ (process-file-shell-command grep-command nil t)
+ (buffer-string)))
+ "\n" t))))
+ (flatten-tree)
+ (seq-remove #'null)
+ (seq-map #'file-name-sans-extension))))
+ (seq-filter (lambda (it)
+ (member (symbol-name (detached--session-id it)) session-ids))
+ sessions)))
+
;;;; Major mode
(defvar detached-list-mode-map