[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/sesman 2b1b624e7a 074/100: Implement friendly session mech
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/sesman 2b1b624e7a 074/100: Implement friendly session mechanism |
Date: |
Tue, 28 Dec 2021 14:06:04 -0500 (EST) |
branch: elpa/sesman
commit 2b1b624e7a05fed9da271a623bee57b58269f820
Author: Vitalie Spinu <spinuvit@gmail.com>
Commit: Vitalie Spinu <spinuvit@gmail.com>
Implement friendly session mechanism
---
sesman.el | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 50 insertions(+), 8 deletions(-)
diff --git a/sesman.el b/sesman.el
index fc58dbae73..c1ad28cb8e 100644
--- a/sesman.el
+++ b/sesman.el
@@ -64,6 +64,14 @@
"Face used to mark buffers."
:group 'sesman)
+(defcustom sesman-use-friendly-sessions t
+ "If non-nil consider friendly sessions when choosing for the current session.
+The definition of friendly sessions is system dependent but usually means
+sessions running in dependency projects."
+ :group 'sesman
+ :type 'boolean
+ :package-version '(sesman . "0.3.2"))
+
;; (defcustom sesman-disambiguate-by-relevance t
;; "If t choose most relevant session in ambiguous situations, otherwise ask.
;; Ambiguity arises when multiple sessions are associated with current
context. By
@@ -353,14 +361,16 @@ or a name of the session, in which case that session is
killed."
;;;###autoload
(defun sesman-info (&optional all)
- "Display linked sessions info.
-When ALL is non-nil, show info for all sessions."
+ "Display info for all current sessions (`sesman-current-sessions').
+In the resulting minibuffer display linked sessions are numbered and the
+other (friendly) sessions are not. When ALL is non-nil, show info for all
+sessions."
(interactive "P")
(let* ((system (sesman--system))
(i 1)
(sessions (if all
(sesman-sessions system t)
- (sesman-linked-sessions system))))
+ (sesman-current-sessions system))))
(if sessions
(message (mapconcat (lambda (ses)
(let ((prefix (if (> (length sessions) 1)
@@ -372,7 +382,9 @@ When ALL is non-nil, show info for all sessions."
(sesman--format-session system ses prefix)))
sessions
"\n"))
- (message "No %s %ssessions" system (if all "" "linked ")))))
+ (message "No %s%s sessions"
+ (if all "" "current ")
+ system))))
;;;###autoload
(defun sesman-link-with-buffer (&optional buffer session)
@@ -527,6 +539,13 @@ provide a more meaningful ordering. If your system objects
are buffers you can
use `sesman-more-recent-p' utility in this method."
(not (string-greaterp (car session1) (car session2))))
+(cl-defgeneric sesman-friendly-session-p (_system _session)
+ "Return non-nil if SESSION is a friendly session in current context.
+The \"friendship\" is system dependent but usually means sessions running in
+dependency projects. Unless SYSTEM has defined a method for this generic, there
+are no friendly sessions."
+ nil)
+
(cl-defgeneric sesman-context-types (_system)
"Return a list of context types understood by SYSTEM.
Contexts must be sorted from most specific to least specific."
@@ -548,7 +567,6 @@ If SORT is non-nil, sessions are sorted in the relevance
order and
(if sort
(delete-dups
(append (sesman-linked-sessions system)
- ;; (sesman-friendly-sessions system)
(sesman--all-system-sessions system t)))
(sesman--all-system-sessions system))))
@@ -565,6 +583,29 @@ list returned from `sesman-context-types'."
(gethash (car assoc) sesman-sessions-hashmap))
(sesman-current-links system nil cxt-types)))))
+(defun sesman-friendly-sessions (system &optional sort)
+ "Return a list of \"friendly\" sessions for the current context.
+The definition of friendly sessions is SYSTEM dependent but usually means
+sessions running in dependency projects. When SORT is non-nil, also sort the
+sessions by relevance."
+ (let ((sessions (seq-filter (lambda (ses) (sesman-friendly-session-p system
ses))
+ (sesman--all-system-sessions system))))
+ (if sort
+ (sesman--sort-sessions system sessions)
+ sessions)))
+
+(defun sesman-current-sessions (system &optional cxt-types)
+ "Return a list of SYSTEM sessions active in the current context.
+If `sesman-use-friendly-sessions' current sessions consist of
+`sesman-linked-sessions' and `sesman-friendly-sessions', otherwise only of
+linked sessions. CXT-TYPES is a list of context types to consider. Defaults to
+the list returned from `sesman-context-types'."
+ (if sesman-use-friendly-sessions
+ (delete-dups
+ (append (sesman-linked-sessions system cxt-types)
+ (sesman-friendly-sessions system 'sort)))
+ (sesman-linked-sessions system cxt-types)))
+
(defun sesman-has-sessions-p (system)
"Return t if there is at least one session registered with SYSTEM."
(let ((system (or system (sesman--system)))
@@ -619,12 +660,12 @@ return a list of sessions, otherwise a single session."
(defun sesman-current-session (system &optional cxt-types)
"Get the most relevant linked session for SYSTEM.
CXT-TYPES is as in `sesman-linked-sessions'."
- (car (sesman-linked-sessions system cxt-types)))
+ (car (sesman-current-sessions system cxt-types)))
(defun sesman-ensure-session (system &optional cxt-types)
"Get the most relevant linked session for SYSTEM or throw if none exists.
CXT-TYPES is as in `sesman-linked-sessions'."
- (or (car (sesman-linked-sessions system cxt-types))
+ (or (sesman-current-session system cxt-types)
(user-error "No linked %s sessions" system)))
(defvar sesman--cxt-abbrevs '(buffer "buf" project "proj" directory "dir"))
@@ -695,7 +736,8 @@ AS-STRING is non-nil, return an equivalent string
representation."
"Link SYSTEM's SESSION to context give by CXT-TYPE and CXT-VAL.
If CXT-TYPE is nil, use the least specific type available in the current
context. If CXT-TYPE is non-nil, and CXT-VAL is not given, retrieve it with
-`sesman-context'."
+`sesman-context'. See also `sesman-link-with-project',
+`sesman-link-with-directory' and `sesman-link-with-buffer'."
(let* ((ses-name (or (car-safe session)
(error "SESSION must be a headed list")))
(cxt-val (or cxt-val
- [nongnu] elpa/sesman 35d6562ad8 006/100: Add more link specific utilities, (continued)
- [nongnu] elpa/sesman 35d6562ad8 006/100: Add more link specific utilities, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 0d8d1bef45 022/100: Version 0.1.1, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman e341db8d97 095/100: Update menu, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 0d3d016732 023/100: Add autoloads for user level commands, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 2e4205c7d9 046/100: Fix return value of sesman-grouped-links, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman ae68b3facf 042/100: [#8] Improve session "info" infrastructure, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 9108444fd8 040/100: Better sorting and de-duplication in a number of core functions, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman ba2756caf7 063/100: Fix compilation warnings, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman fcdb6846f3 061/100: Make checkdoc happy, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 602d818dd0 073/100: Autoload sesman keymap, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 2b1b624e7a 074/100: Implement friendly session mechanism,
ELPA Syncer <=
- [nongnu] elpa/sesman 19151a8b60 065/100: Add colors for marking dir, proj and buf in listings, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 1f5b2b2338 075/100: More consistent empty prefix in sesman-info, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 59f4a2442e 077/100: Simplify system API by subsuming sesman-linked/friendly-sessions into sesman-sessions, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 4b2507d1ee 076/100: Optimize sesman-current-session, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman edee869c20 096/100: Sesman menu: Add Browser, Move Unlink, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 93123f6cef 093/100: Rename seman-menu-open -> sesman-menu-open, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 966c13812f 088/100: [Fix #14] Rewrite the usage of when-let*, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman b527f7a638 043/100: Make sesman-system permanent local, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 95f8354d1a 041/100: Add sesman-relevant-[link|session]-p functions, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman cf7997e279 035/100: Add sesman-project generic, ELPA Syncer, 2021/12/28