Narrow completion results to only templates
In starting a new session with mindstream-new, the completion candidates should only allow templates rather than any file. So if something like M-p is used to insert a recent selection according to savehist-mode (or prescient), it should ideally use a narrowed history consisting only of applicable files, and thus pick the most recently selected template.
See #13 for more details.
Hi @countvajhula,
How about something like this? In #13, use of completing-read is suggested.
The simple example below shows how it might be done. The variable mindstream-template-history records the history.
With this example, I am also suggesting another idea to explore. With the current design, templates are directory names. I believe this design has lead to the need for mindstream--session-file-for-template to do some heuristics to determine a single file for a new session.
You could simplify this part of design to let the user select a template file with completing-read like the example. You can keep the logic to determine the major mode as is. When you need to get the directory name of the template file, it's as easy as (file-name-directory template-file) like the example does.
What do you think? Just a suggestion.
(defun mindstream-new (&optional template)
"Start a new anonymous session.
[... omitted for brevity...]"
(interactive)
(let ((template (or template (mindstream--completing-read-template))))
(switch-to-buffer (mindstream--new template))))
(defvar mindstream-template-history nil)
(defun mindstream--completing-read-template ()
"Completion for template."
(let* ((files (directory-files-recursively
mindstream-template-path
directory-files-no-dot-files-regexp))
(template-file
(completing-read "Which template? " files nil t nil
'mindstream-template-history)))
;; The current design requires the directory component of file name
;; be a template.
(file-name-directory template-file)))
How about something like this? In #13, use of completing-read is suggested. The simple example below shows how it might be done. The variable mindstream-template-history records the history.
That looks great, thank you!
With this example, I am also suggesting another idea to explore. With the current design, templates are directory names. I believe this design has lead to the need for mindstream--session-file-for-template to do some heuristics to determine a single file for a new session.
You could simplify this part of design to let the user select a template file with completing-read like the example. You can keep the logic to determine the major mode as is. When you need to get the directory name of the template file, it's as easy as (file-name-directory template-file) like the example does.
Currently, you can already select the specific file when loading a session, but not when starting a new session. I actually can't recall the reason, but atm I don't see why we shouldn't support it.
I've gone ahead and adopted the first part of the suggestion here for completing read and will take a look at selecting a file soon.
@countvajhula Thank you. Please see continuation in #9 (I sent a PR related to this -- only to illustrate my ideas in concrete code).
This was fixed in #20 and related work.