[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dtache d32b5752d6 034/158: Implement new deduplication
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dtache d32b5752d6 034/158: Implement new deduplication strategy |
Date: |
Wed, 19 Jan 2022 18:57:42 -0500 (EST) |
branch: externals/dtache
commit d32b5752d6468eb8f634510c44fe8a5944a10911
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>
Implement new deduplication strategy
This patch removes the invisible cookies that were previously added in
order to disambiguate sessions that have the same command. The new
approach is to add a numeric identifier after the command.
---
dtache.el | 53 +++++++++++++++++++++++++++++++----------------------
1 file changed, 31 insertions(+), 22 deletions(-)
diff --git a/dtache.el b/dtache.el
index e31c565795..81a9063237 100644
--- a/dtache.el
+++ b/dtache.el
@@ -384,7 +384,8 @@ nil before closing."
(defun dtache-select-session ()
"Return selected session."
(dtache-update-sessions)
- (dtache-completing-read dtache--sessions))
+ (let ((sessions dtache--sessions))
+ (dtache-completing-read sessions)))
(defun dtache-update-sessions ()
"Update `dtache' sessions.
@@ -420,12 +421,31 @@ Sessions running on current host or localhost are
updated."
(defun dtache-session-candidates (sessions)
"Return an alist of SESSIONS candidates."
- (seq-map (lambda (it)
- (let ((s (format #("%s\0%s" 2 5 (invisible t))
- (dtache--session-truncate-command it)
- (dtache--session-short-id it))))
- (prog1 s (put-text-property 0 1 'dtache--data it s))))
- sessions))
+ (thread-last sessions
+ (seq-map (lambda (it)
+ `(,(dtache--session-truncate-command it)
+ . ,it)))
+ (dtache--session-deduplicate)
+ (seq-map (lambda (it)
+ ;; Max width is the ... padding + width of identifier
+ (setcar it (truncate-string-to-width (car it) (+ 3 6
dtache-max-command-length) 0 ?\s))
+ it))))
+
+(defun dtache--session-deduplicate (sessions)
+ "Make car of SESSIONS unique by adding an identifier to it."
+ (let* ((ht (make-hash-table :test #'equal :size (length sessions)))
+ (identifier-width 6)
+ (reverse-sessions (seq-reverse sessions)))
+ (dolist (session reverse-sessions)
+ (if-let (count (gethash (car session) ht))
+ (setcar session (format "%s%s" (car session)
+ (truncate-string-to-width
+ (propertize (format " (%s)" (puthash (car
session) (1+ count) ht)) 'face 'dtache-identifier-face)
+ identifier-width 0 ?\s)))
+ (puthash (car session) 0 ht)
+ (setcar session (format "%s%s" (car session) (make-string
identifier-width ?\s)))))
+ (seq-reverse reverse-sessions)))
+
(defun dtache-session-annotation (session)
"Return annotation string for SESSION."
(mapconcat
@@ -682,14 +702,13 @@ Sessions running on current host or localhost are
updated."
(defun dtache--session-truncate-command (session)
"Return a truncated string representation of SESSION's command."
(let ((command (dtache--session-command session))
- (part-length (- dtache-max-command-length 3)))
+ (truncated-command))
(if (<= (length command) dtache-max-command-length)
- (let ((padding-length (- dtache-max-command-length (length command))))
- (concat command (make-string padding-length ?\s)))
+ command
(concat
- (substring command 0 (/ part-length 2))
+ (substring command 0 (/ dtache-max-command-length 2))
"..."
- (substring command (- (length command) (/ part-length 2)) (length
command))))))
+ (substring command (- (length command) (/ dtache-max-command-length 2))
(length command))))))
(defun dtache--session-short-id (session)
"Return the short representation of the SESSION's id."
@@ -825,16 +844,6 @@ Sessions running on current host or localhost are
updated."
(when-let ((callback (dtache--session-callback-function session)))
(funcall callback session))))
-(defun dtache--eat-cookie (&rest _)
- "Eat the disambiguation cookie in the minibuffer."
- (let* ((pos (minibuffer-prompt-end))
- (max (point-max)))
- (while (and (< pos max) (/= 0 (char-after pos)))
- (setq pos (1+ pos)))
- (when (< pos max)
- (add-text-properties pos (next-property-change pos nil max)
- '(invisible t rear-nonsticky t)))))
-
(defun dtache--kill-processes (pid)
"Kill PID and all of its children."
(let ((child-processes
- [elpa] externals/dtache d574161815 042/158: Simplify buffer handling, (continued)
- [elpa] externals/dtache d574161815 042/158: Simplify buffer handling, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 1878cefb2f 038/158: Remove embark dependency, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 3c61776c7f 014/158: Fix dtache initialization, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 7c07950642 043/158: Implement better encapsulation of database, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 42569d1c5f 036/158: Update broken tests, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache ddf9bb6ade 039/158: Add action map example, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache c70c9366a5 028/158: Update test to test with/without dtache-env, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache d5aa90356a 029/158: Add CHANGELOG to project, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 4751b4d812 046/158: Implement a general timer function, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 1bc60af5a0 040/158: Update changelog and readme, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache d32b5752d6 034/158: Implement new deduplication strategy,
ELPA Syncer <=
- [elpa] externals/dtache 36be431e18 032/158: Add workaround solution for MacOS users, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 80fca01eae 037/158: Update CHANGELOG, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 8769db2acb 051/158: Fix error in dtache-shell-attach, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache a36e89486f 055/158: Add package dtache-eshell, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache eab014faad 050/158: Version 0.2, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 9a2f4a4d43 057/158: Introduce caching variable for candidates, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 02b93a3778 060/158: Minor cleanup, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache d693d4c386 065/158: Update README with links to blog posts, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 69b001d0e5 069/158: Make eshell-preoutput-filter-functions local, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache be23732c84 079/158: Update documentation in README, ELPA Syncer, 2022/01/19