emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dtache 182ab7ccc6 064/158: Add integration with consult


From: ELPA Syncer
Subject: [elpa] externals/dtache 182ab7ccc6 064/158: Add integration with consult
Date: Wed, 19 Jan 2022 18:57:58 -0500 (EST)

branch: externals/dtache
commit 182ab7ccc6807879add58ab8b336e62087fcb967
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>

    Add integration with consult
    
    This patch adds the dtache-consult.el library which provides the
    integration with consult. The package implements a command
    dtache-consult-session which is supposed to be used as a replacement
    for dtache-open-session.
    
    The package also implements different session sources which the users
    can use to narrow the list of sessions with.
---
 CHANELOG.org      |   1 +
 README.org        |  25 ++++++--
 dtache-consult.el | 183 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 dtache.el         |   6 +-
 4 files changed, 210 insertions(+), 5 deletions(-)

diff --git a/CHANELOG.org b/CHANELOG.org
index 679db88233..357527d8e6 100644
--- a/CHANELOG.org
+++ b/CHANELOG.org
@@ -4,6 +4,7 @@
 
 * Development
 
+- Add integration with the =consult= package through =dtache-consult.el=.
 - Add support for =eshell= through the =dtache-eshell= package.
 - macOS (monitor) support is added to the package.
 
diff --git a/README.org b/README.org
index 1b57eb930d..fac719e004 100644
--- a/README.org
+++ b/README.org
@@ -154,6 +154,27 @@ These are commands that the package provides and which the 
user is expected to b
 
 To detach from a session simply use =C-c C-c=.
 
+** Consult
+
+A =use-package= configuration of the =dtache-consult= package. This package 
provides the integration with the [[https://github.com/minad/consult][consult]] 
package.
+
+#+begin_src elisp
+  (use-package dtache-consult
+    :commands dtache-consult-session)
+#+end_src
+
+This package provides the =dtache-consult-session= command which is a 
replacement for =dtache-open-session=. The difference is that the consult 
command provides multiple session sources, which is defined in the 
=dtache-consult-sources= variable. Users can customize which sources to use, as 
well as use individual sources in other =consult= commands, such as 
=consult-buffer=. The users can also narrow the list of sessions by entering a 
key. The list of supported keys are:
+
+| Type                  | Key |
+|-----------------------+-----|
+| Active sessions       | a   |
+| Inactive sessions     | i   |
+| Successful sessions   | s   |
+| Failed sessions       | f   |
+| Local host sessions   | l   |
+| Remote host sessions  | r   |
+| Current host sessions | c   |
+
 ** Embark
 
 The user have the possibility to integrate =dtache= with the package 
[[https://github.com/oantolin/embark/][embark]]. The =dtache-action-map= can be 
reused for this purpose, so the user doesn't need to bind it to any key. 
Instead the user simply adds the following to their =dtache= configuration in 
order to get embark actions for =dtache-open-session=.
@@ -163,10 +184,6 @@ The user have the possibility to integrate =dtache= with 
the package [[https://g
   (add-to-list 'embark-keymap-alist '(dtache . embark-dtache-map))
 #+end_src
 
-** Consult
-
-The [[https://gitlab.com/niklaseklund/consult-dtache][consult-dtache]] package 
provides the integration of =dtache= 
[[https://github.com/minad/consult][consult]]. The benefit of using this 
package is that the user has the ability to narrow the list of sessions based 
on different criterion. Since this package has external dependencies it is 
provided in its own repository.
-
 ** Alert
 
 By default =dtache= uses the echo area to notify the user when a session has 
finished. An alternative is to utilize the 
[[https://github.com/jwiegley/alert][alert]] package to get a system 
notification instead.
diff --git a/dtache-consult.el b/dtache-consult.el
new file mode 100644
index 0000000000..8fc33488ae
--- /dev/null
+++ b/dtache-consult.el
@@ -0,0 +1,183 @@
+;;; dtache-consult.el --- Dtache interface using Consult multi sources -*- 
lexical-binding: t -*-
+
+;; Copyright (C) 2021-2022 Niklas Eklund
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This package integrates `dtache' with `consult'[1].  The package
+;; provides a command `dtache-consult-session' which provides multiple session 
sources.
+;;
+;; [1] https://github.com/minad/consult
+
+;;; Code:
+
+;;;; Requirements
+
+(require 'dtache)
+
+(declare-function consult--multi "consult")
+
+;;;; Variables
+
+(defcustom dtache-consult-sources
+  '(dtache-consult--source-session
+    dtache-consult--source-active-session
+    dtache-consult--source-inactive-session
+    dtache-consult--source-success-session
+    dtache-consult--source-failure-session
+    dtache-consult--source-local-session
+    dtache-consult--source-remote-session
+    dtache-consult--source-current-session)
+  "Sources used by `dtache-consult-session'.
+
+See `consult-multi' for a description of the source values."
+  :type '(repeat symbol)
+  :group 'dtache)
+
+(defvar dtache-consult--source-session
+  `(:category dtache
+    :annotate dtache-session-annotation
+    :action (lambda (x) (dtache-open-session (dtache--decode-session x)))
+    :items
+    ,(lambda ()
+       (seq-map #'car (dtache-session-candidates (dtache-get-sessions)))))
+  "All `dtache' sessions as a source for `consult'.")
+
+(defvar dtache-consult--source-active-session
+  `(:narrow (?a . "Active")
+    :hidden t
+    :category dtache
+    :annotate dtache-session-annotation
+    :action (lambda (x) (dtache-open-session (dtache--decode-session x)))
+    :items
+    ,(lambda ()
+       (mapcar #'car
+               (seq-filter
+                (lambda (x)
+                  (dtache--session-active (cdr x)))
+                (dtache-session-candidates (dtache-get-sessions))))))
+  "Active `dtache' sessions as a source for `consult'.")
+
+(defvar dtache-consult--source-inactive-session
+  `(:narrow (?i . "Inactive")
+    :hidden t
+    :category dtache
+    :annotate dtache-session-annotation
+    :action (lambda (x) (dtache-open-session (dtache--decode-session x)))
+    :items
+    ,(lambda ()
+       (mapcar #'car
+               (seq-remove
+                (lambda (x)
+                  (dtache--session-active (cdr x)))
+                (dtache-session-candidates (dtache-get-sessions))))))
+  "Inactive `dtache' sessions as a source for `consult'.")
+
+(defvar dtache-consult--source-failure-session
+  `(:narrow (?f . "Failure")
+    :hidden t
+    :category dtache
+    :annotate dtache-session-annotation
+    :action (lambda (x) (dtache-open-session (dtache--decode-session x)))
+    :items
+    ,(lambda ()
+       (mapcar #'car
+               (seq-filter
+                (lambda (x)
+                  (eq 'failure (dtache--session-status (cdr x))))
+                (dtache-session-candidates (dtache-get-sessions))))))
+  "Failed `dtache' sessions as a source for `consult'.")
+
+(defvar dtache-consult--source-success-session
+  `(:narrow (?s . "Success")
+    :hidden t
+    :category dtache
+    :annotate dtache-session-annotation
+    :action (lambda (x) (dtache-open-session (dtache--decode-session x)))
+    :items
+    ,(lambda ()
+       (mapcar #'car
+               (seq-filter
+                (lambda (x)
+                  (eq 'success (dtache--session-status (cdr x))))
+                (dtache-session-candidates (dtache-get-sessions))))))
+  "Successful `dtache' sessions as a source for `consult'.")
+
+(defvar dtache-consult--source-local-session
+  `(:narrow (?l . "Local Host")
+    :hidden t
+    :category dtache
+    :annotate dtache-session-annotation
+    :action (lambda (x) (dtache-open-session (dtache--decode-session x)))
+    :items
+    ,(lambda ()
+       (let ((host "localhost"))
+         (mapcar #'car
+                 (seq-filter
+                  (lambda (x)
+                    (string= (dtache--session-host (cdr x)) host))
+                  (dtache-session-candidates (dtache-get-sessions))))))
+    "Local host `dtache' sessions as a source for `consult'."))
+
+(defvar dtache-consult--source-remote-session
+  `(:narrow (?r . "Remote Host")
+    :hidden t
+    :category dtache
+    :annotate dtache-session-annotation
+    :action (lambda (x) (dtache-open-session (dtache--decode-session x)))
+    :items
+    ,(lambda ()
+       (let ((host "localhost"))
+         (mapcar #'car
+                 (seq-remove
+                  (lambda (x)
+                    (string= (dtache--session-host (cdr x)) host))
+                  (dtache-session-candidates (dtache-get-sessions)))))))
+  "Remote host `dtache' sessions as a source for `consult'.")
+
+(defvar dtache-consult--source-current-session
+  `(:narrow (?c . "Current Host")
+    :hidden t
+    :category dtache
+    :annotate dtache-session-annotation
+    :action (lambda (x) (dtache-open-session (dtache--decode-session x)))
+    :items
+    ,(lambda ()
+       (let ((host (dtache--host)))
+         (mapcar #'car (seq-filter
+                        (lambda (x)
+                          (string= (dtache--session-host (cdr x)) host))
+                        (dtache-session-candidates (dtache-get-sessions)))))))
+  "Current host `dtache' sessions as a source for `consult'.")
+
+;;;; Commands
+
+;;;###autoload
+(defun dtache-consult-session ()
+  "Enhanced `dtache-open-session' command."
+  (interactive)
+  (unless (require 'consult nil 'noerror)
+    (error "Install Consult to use dtache-consult"))
+  (consult--multi dtache-consult-sources
+                  :prompt "Select session: "
+                  :require-match t
+                  :sort nil))
+
+(provide 'dtache-consult)
+
+;;; dtache-consult.el ends here
diff --git a/dtache.el b/dtache.el
index 59921bc642..04b255ae2c 100644
--- a/dtache.el
+++ b/dtache.el
@@ -622,7 +622,7 @@ Optionally make the path LOCAL to host."
                            metadata
                          (complete-with-action action candidates string 
predicate))))
          (cand (completing-read "Select session: " collection nil t)))
-    (cdr (assoc cand candidates))))
+    (dtache--decode-session cand)))
 
 ;;;; Support functions
 
@@ -742,6 +742,10 @@ Optionally make the path LOCAL to host."
          '(:seconds 0.5 :repeat 0.5 :function run-with-idle-timer)))
     (dtache--session-timer-monitor session)))
 
+(defun dtache--decode-session (item)
+  "Return the session assicated with ITEM."
+  (cdr (assoc item dtache--session-candidates)))
+
 ;;;;; Database
 
 (defun dtache--db-initialize ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]