[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/detached 4321d628b4 1/3: Add possibility to narrow sess
From: |
ELPA Syncer |
Subject: |
[elpa] externals/detached 4321d628b4 1/3: Add possibility to narrow sessions based on output |
Date: |
Fri, 23 Sep 2022 09:57:28 -0400 (EDT) |
branch: externals/detached
commit 4321d628b463c1bfacfbb2632f79f5c0ca5daff4
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>
Add possibility to narrow sessions based on output
Add a narrow function which narrows to sessions with an output that
matches a regular expression.
---
CHANGELOG.org | 1 +
detached-list.el | 117 ++++++++++++++++++++++++++++++++++++++++++-------------
detached.el | 5 +++
3 files changed, 95 insertions(+), 28 deletions(-)
diff --git a/CHANGELOG.org b/CHANGELOG.org
index 406ae67b96..84bb76036e 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -8,6 +8,7 @@
- Add concept of =filters= to quickly apply a set of narrow criteria.
- Speed up initialization of sessions.
- Narrow criteria are persistent and applied when resuming detached list
sessions.
+- Add narrow criterion which searches through the output of all sessions in
detached list which matches a regexp.
* Version 0.9.1 (2022-09-22)
diff --git a/detached-list.el b/detached-list.el
index deb9ddc754..3d3d09cb63 100644
--- a/detached-list.el
+++ b/detached-list.el
@@ -190,9 +190,62 @@ Optionally SUPPRESS-OUTPUT."
(when hostname
(detached-list-narrow-sessions
`((,(concat "Host: " hostname) .
- ,(lambda (session)
- (string-match hostname
- (car (detached--session-host session)))))
+ ,(lambda (sessions)
+ (seq-filter (lambda (it)
+ (string-match hostname
+ (car (detached--session-host it))))
+ sessions)))
+ ,@detached-list--filters))))
+
+(defun detached-list-narrow-output-regexp (regexp)
+ "Narrow to sessions which output contain REGEXP."
+ (interactive
+ (list (read-regexp
+ "Filter session outputs containing (regexp): ")))
+ (when regexp
+ (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
+ "-l"
+ ,@includes
+ "-snir"
+ ,(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-list--filters))))
(defun detached-list-narrow-regexp (regexp)
@@ -203,9 +256,11 @@ Optionally SUPPRESS-OUTPUT."
(when regexp
(detached-list-narrow-sessions
`((,(concat "Regexp: " regexp) .
- ,(lambda (session)
- (string-match regexp
- (detached--session-command session))))
+ ,(lambda (sessions)
+ (seq-filter (lambda (it)
+ (string-match regexp
+ (detached--session-command it)))
+ sessions)))
,@detached-list--filters))))
(defun detached-list-narrow-local ()
@@ -213,8 +268,8 @@ Optionally SUPPRESS-OUTPUT."
(interactive)
(detached-list-narrow-sessions
`(("Local" .
- ,(lambda (session)
- (detached--local-session-p session)))
+ ,(lambda (sessions)
+ (seq-filter #'detached--local-session-p sessions)))
,@detached-list--filters)))
(defun detached-list-narrow-remote ()
@@ -222,8 +277,8 @@ Optionally SUPPRESS-OUTPUT."
(interactive)
(detached-list-narrow-sessions
`(("Remote" .
- ,(lambda (session)
- (detached--remote-session-p session)))
+ ,(lambda (sessions)
+ (seq-filter #'detached--remote-session-p sessions)))
,@detached-list--filters)))
(defun detached-list-select-filter ()
@@ -250,9 +305,12 @@ Optionally SUPPRESS-OUTPUT."
(when origin
(detached-list-narrow-sessions
`((,(concat "Origin: " origin) .
- ,(lambda (session)
- (string-match origin
- (symbol-name (detached--session-origin session)))))
+ ,(lambda (sessions)
+ (seq-filter
+ (lambda (it)
+ (string-match origin
+ (symbol-name (detached--session-origin it))))
+ sessions)))
,@detached-list--filters))))
(defun detached-list-narrow-active ()
@@ -260,8 +318,8 @@ Optionally SUPPRESS-OUTPUT."
(interactive)
(detached-list-narrow-sessions
`(("Active" .
- ,(lambda (session)
- (detached--active-session-p session)))
+ ,(lambda (sessions)
+ (seq-filter #'detached--active-session-p sessions)))
,@detached-list--filters)))
(defun detached-list-narrow-inactive ()
@@ -269,8 +327,8 @@ Optionally SUPPRESS-OUTPUT."
(interactive)
(detached-list-narrow-sessions
`(("Inactive" .
- ,(lambda (session)
- (null (detached--active-session-p session))))
+ ,(lambda (sessions)
+ (seq-remove #'detached--active-session-p sessions)))
,@detached-list--filters)))
(defun detached-list-narrow-success ()
@@ -278,8 +336,10 @@ Optionally SUPPRESS-OUTPUT."
(interactive)
(detached-list-narrow-sessions
`(("Success" .
- ,(lambda (session)
- (eq 'success (car (detached--session-status session)))))
+ ,(lambda (sessions)
+ (seq-filter (lambda (it)
+ (eq 'success (car (detached--session-status it))))
+ sessions)))
,@detached-list--filters)))
(defun detached-list-narrow-failure ()
@@ -287,8 +347,10 @@ Optionally SUPPRESS-OUTPUT."
(interactive)
(detached-list-narrow-sessions
`(("Failure" .
- ,(lambda (session)
- (eq 'failure (car (detached--session-status session)))))
+ ,(lambda (sessions)
+ (seq-filter (lambda (it)
+ (eq 'failure (car (detached--session-status it))))
+ sessions)))
,@detached-list--filters)))
(defun detached-list-mark-regexp (regexp)
@@ -528,13 +590,11 @@ If prefix-argument is provided unmark instead of mark."
(defun detached-list--get-filtered-sessions ()
"Return a list of filtered sessions."
- (thread-last (detached-get-sessions)
- (seq-filter (lambda (session)
- (seq-every-p
- (lambda (it) it)
- (seq-map (lambda (filter)
- (funcall (cdr filter) session))
- detached-list--filters))))))
+ (let ((sessions (detached-get-sessions)))
+ (seq-do (lambda (filter)
+ (setq sessions (funcall (cdr filter) sessions)))
+ detached-list--filters)
+ sessions))
;;;; Major mode
@@ -554,6 +614,7 @@ If prefix-argument is provided unmark instead of mark."
(define-key map (kbd "n o") #'detached-list-narrow-origin)
(define-key map (kbd "n r") #'detached-list-narrow-remote)
(define-key map (kbd "n s") #'detached-list-narrow-success)
+ (define-key map (kbd "n /") #'detached-list-narrow-output-regexp)
(define-key map (kbd "n %") #'detached-list-narrow-regexp)
(define-key map (kbd "q") #'detached-list-quit)
(define-key map (kbd "r") #'detached-list-rerun-session)
diff --git a/detached.el b/detached.el
index a70be71200..f28784a1a6 100644
--- a/detached.el
+++ b/detached.el
@@ -81,6 +81,11 @@
:type 'string
:group 'detached)
+(defcustom detached-grep-program "grep"
+ "The name of the grep program."
+ :type 'string
+ :group 'detached)
+
(defcustom detached-shell-program shell-file-name
"Path to the shell to run the dtach command in."
:type 'string