branch: elpa/sesman commit 27bd3bf4575f09417c7353f0c1b1788f050aee20 Author: Vitalie Spinu <spinu...@gmail.com> Commit: Vitalie Spinu <spinu...@gmail.com>
Remove disambiguation defcustom and simplify sesman-ensure-linked-session --- README.md | 2 +- sesman.el | 42 +++++++++++++----------------------------- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index c6db29d8f8..4ad1bdb730 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Consists of - lifecycle management commands (`sesman-start`, `sesman-kill` and `sesman-restart`), and - association management commands (`sesman-link-with-buffer`, `sesman-link-with-directory`, `sesman-link-with-project` and `sesman-unlink`). -From the user's prospective the work-flow is as follow. Start a session, either with `sesman-start` (`C-c C-s C-s`) or some of the system specific commands (`run-xyz`, `xyz-jack-in` etc). On startup each session is automatically associated with the least specific context (commonly a project). In the most common case the user has only one session open per project. In such case, no ambiguity arises when a system retrieves the current session. If multiple sessions are associated with the cu [...] +From the user's prospective the work-flow is as follow. Start a session, either with `sesman-start` (`C-c C-s C-s`) or some of the system specific commands (`run-xyz`, `xyz-jack-in` etc). On startup each session is automatically associated with the least specific context (commonly a project). In the most common case the user has only one session open per project. In such case, no ambiguity arises when a system retrieves the current session. If multiple sessions are associated with the cu [...] By default links with projects and directories are many-to-many in the sense that any session can be linked to multiple context and each context can be associated with multiple sessions. Buffers instead are 1-to-many. One buffer can be associated with only one session and a session can be associated with multiple buffers. This behavior is controlled by a custom `sesman-single-link-context-types`. diff --git a/sesman.el b/sesman.el index c0d5c44b93..9fe6cc5ae7 100644 --- a/sesman.el +++ b/sesman.el @@ -49,14 +49,14 @@ :prefix "sesman-" :group 'tools) -(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 -default only projects could be associated with multiple sessions. See -`sesman-single-link-contexts' in order to change that. Relevance is decided by -system's implementation, see `sesman-more-relevant-p'." - :group 'sesman - :type 'boolean) +;; (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 +;; default only projects could be associated with multiple sessions. See +;; `sesman-single-link-contexts' in order to change that. Relevance is decided by +;; system's implementation, see `sesman-more-relevant-p'." +;; :group 'sesman +;; :type 'boolean) (defcustom sesman-single-link-context-types '(buffer) "List of context types to which at most one session can be linked." @@ -508,28 +508,12 @@ list returned from `sesman-context-types'." (gethash (car assoc) sesman-sessions-hashmap)) (sesman-current-links system cxt-types)))) -(defun sesman-ensure-linked-session (system &optional prompt ask-new ask-all) +(defun sesman-ensure-linked-session (system) "Ensure that at least one SYSTEM session is linked to the current context. -If there is an unambiguous link in place, return that session, otherwise -ask for a session with PROMPT. ASK-NEW and ASK-ALL have an effect only when -there are multiple associations and `sesman-disambiguate-by-relevance' is -nil, in which case ASK-NEW and ASK-ALL are passed directly to -`sesman-ask-for-session'." - (let ((prompt (or prompt (format "%s session: " (sesman--cap-system-name system)))) - (sessions (sesman-linked-sessions system))) - (cond - ;; 0. No sessions; throw - ((null sessions) - (user-error "No linked %s sessions in current context" system)) - ;; 1. Single association, or auto-disambiguate; return first - ((or sesman-disambiguate-by-relevance - (eq (length sessions) 1)) - (if ask-all - sessions - (car sessions))) - ;; 2. Multiple ambiguous associations; ask - (sessions - (sesman-ask-for-session system prompt sessions ask-new ask-all))))) +If there is at least one linked session, return the most relevant session. +Otherwise throw an error." + (or (car (sesman-linked-sessions system)) + (user-error "No %s sessions linked to current context" system))) (defun sesman-session-links (system session &optional as-string) "Retrieve all links for SYSTEM's SESSION from the global `SESSION-LINKS'.