[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/sesman 59f4a2442e 077/100: Simplify system API by subsumin
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/sesman 59f4a2442e 077/100: Simplify system API by subsuming sesman-linked/friendly-sessions into sesman-sessions |
Date: |
Tue, 28 Dec 2021 14:06:04 -0500 (EST) |
branch: elpa/sesman
commit 59f4a2442e59c16bbc4e9c356d47b2e2e56299eb
Author: Vitalie Spinu <spinuvit@gmail.com>
Commit: Vitalie Spinu <spinuvit@gmail.com>
Simplify system API by subsuming sesman-linked/friendly-sessions into
sesman-sessions
---
sesman.el | 95 ++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 48 insertions(+), 47 deletions(-)
diff --git a/sesman.el b/sesman.el
index e0456dbd84..9e0013627a 100644
--- a/sesman.el
+++ b/sesman.el
@@ -121,7 +121,7 @@ Can be either a symbol, or a function returning a symbol.")
(when ses
(list ses))))
((or (equal which '(4)) (eq which 'linked))
- (sesman-linked-sessions system))
+ (sesman--linked-sessions system))
((or (equal which '(16)) (eq which 'all) (eq which t))
(sesman--all-system-sessions system 'sort))
;; session itself
@@ -192,6 +192,23 @@ Can be either a symbol, or a function returning a symbol.")
sesman-system)
(error "No `sesman-system' in buffer `%s'" (current-buffer))))
+(defun sesman--linked-sessions (system &optional sort cxt-types)
+ (let* ((system (or system (sesman--system)))
+ (cxt-types (or cxt-types (sesman-context-types system))))
+ ;; just in case some links are lingering due to user errors
+ (sesman--clear-links)
+ (delete-dups
+ (mapcar (lambda (assoc)
+ (gethash (car assoc) sesman-sessions-hashmap))
+ (sesman-current-links system nil cxt-types)))))
+
+(defun sesman--friendly-sessions (system &optional sort)
+ (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--all-system-sessions (&optional system sort)
"Return a list of sessions registered with SYSTEM.
If SORT is non-nil, sort in relevance order."
@@ -558,52 +575,38 @@ Contexts must be sorted from most specific to least
specific."
(let ((system (or system (sesman--system))))
(gethash (cons system session-name) sesman-sessions-hashmap)))
-(defun sesman-sessions (system &optional sort)
- "Return a list of all sessions registered with SYSTEM.
-If SORT is non-nil, sessions are sorted in the relevance order and
-`sesman-linked-sessions' lead the list."
+(defun sesman-sessions (system &optional sort type cxt-types)
+ "Return a list of sessions registered with SYSTEM.
+When TYPE is either 'all or nil return all sessions registered with system,
when
+'linked, only linked sessions to the current context, when 'friendly return
only
+friendly sessions. If SORT is non-nil, sessions are sorted in the relevance
+order with linked sessions leading the list. CXT-TYPES is a list of context
+types to consider for linked sessions."
(let ((system (or system (sesman--system))))
- (if sort
- (delete-dups
- (append (sesman-linked-sessions system)
- (sesman--all-system-sessions system t)))
- (sesman--all-system-sessions system))))
-
-(defun sesman-linked-sessions (system &optional cxt-types)
- "Return a list of SYSTEM sessions linked in current context.
-CXT-TYPES is a list of context types to consider. Defaults to the
-list returned from `sesman-context-types'."
- (let* ((system (or system (sesman--system)))
- (cxt-types (or cxt-types (sesman-context-types system))))
- ;; just in case some links are lingering due to user errors
- (sesman--clear-links)
- (delete-dups
- (mapcar (lambda (assoc)
- (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)))
+ (cond
+ ((eq type 'linked)
+ (sesman--linked-sessions system sort cxt-types))
+ ((eq type 'friendly)
+ (sesman--friendly-sessions system sort))
+ ((memq type '(all nil))
+ (if sort
+ (delete-dups
+ (append (sesman--linked-sessions system t cxt-types)
+ (sesman--all-system-sessions system t)))
+ (sesman--all-system-sessions system)))
+ (t (error "Invalid session TYPE argument %s" type)))))
(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'."
+Sessions are ordered by the relevance order and linked sessions come first. If
+`sesman-use-friendly-sessions' current sessions consist of linked and 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)))
+ (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."
@@ -658,14 +661,13 @@ return a list of sessions, otherwise a single session."
(defun sesman-current-session (system &optional cxt-types)
"Get the most relevant current session for the SYSTEM.
-CXT-TYPES is a list of context types to consider. See `sesman-current-sessions'
-for further details."
- (or (car (sesman-linked-sessions system cxt-types))
- (car (sesman-friendly-sessions system 'sort))))
+CXT-TYPES is a list of context types to consider."
+ (or (car (sesman--linked-sessions system cxt-types))
+ (car (sesman--friendly-sessions system 'sort))))
(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'."
+CXT-TYPES is a list of context types to consider."
(or (sesman-current-session system cxt-types)
(user-error "No linked %s sessions" system)))
@@ -855,7 +857,6 @@ session (list SESSION-NAME OBJECT)."
(error "%s session '%s' does not exist"
(sesman--cap-system-name system) session-name)))))
-
(defun sesman-remove-object (system session-name object &optional
auto-unregister no-error)
"Remove (destructively) OBJECT from session SESSION-NAME of SYSTEM.
If SESSION-NAME is nil, retrieve the session with
- [nongnu] elpa/sesman 0d3d016732 023/100: Add autoloads for user level commands, (continued)
- [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, 2021/12/28
- [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 <=
- [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
- [nongnu] elpa/sesman 0ea1d3e645 048/100: [Fix #7] Implement WHICH argument in `sesman-restart`, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman 0e38d4e427 057/100: Remove unnecessary autoloads, ELPA Syncer, 2021/12/28
- [nongnu] elpa/sesman e4775a2e81 084/100: Remove sesman--expand-path-maybe, ELPA Syncer, 2021/12/28