added (autoscratch-select) for multiple-choice triggers

This commit is contained in:
Thomas von Dein
2017-07-17 16:57:53 +02:00
parent 0054c07ad3
commit 8e7c476216

View File

@@ -76,14 +76,26 @@
(defcustom autoscratch-triggers-alist (defcustom autoscratch-triggers-alist
'(("[(;]" . (emacs-lisp-mode)) '(("[(;]" . (emacs-lisp-mode))
("#" . (conf-unix-mode)) ("#" . (autoscratch-select
'(("perl" . (cperl-mode))
("ruby" . (ruby-mode))
("python" . (python-mode))
("conf" . (conf-unix-mode))
("shell" . (shell-script-mode)))))
("[-a-zA-Z0-9]" . (text-mode)) ("[-a-zA-Z0-9]" . (text-mode))
("/" . (c-mode)) ("/" . (c-mode))
("*" . (progn (insert " ") (org-mode))) ("*" . (progn (insert " ") (org-mode)))
("." . (fundamental-mode))) ("." . (fundamental-mode)))
"Default trigger alist for autoscratch mode. "Default trigger alist for autoscratch mode.
This list triggers after the first character entered." This list triggers after the first character entered.
You can customize this variable directly or use `add-to-list'
to add more triggers.
In case there are more possibilities for a character, you can
use `autoscratch-select' to make autoscratch ask interactively
for a major mode to switch to, which see. A good example for
such a character is # which is the comment-char in many modes."
:group 'autoscratch :group 'autoscratch
:type 'list) :type 'list)
@@ -135,6 +147,28 @@ Executes `autoscratch-rename-hook' afterwards."
(switch-to-buffer buf) (switch-to-buffer buf)
(autoscratch-mode))) (autoscratch-mode)))
(defun autoscratch-select(modelist)
"Interactively ask for major mode to switch to.
Argument MODELIST must be an alist where the car of each
pair must be a name and the cdr some arbitrary emacs lisp
form.
Example for MODELIST:
'((\"perl\" . (cperl-mode))
(\"ruby\" . (ruby-mode))
(\"python\" . (python-mode))
(\"shell\" . (shell-script-mode))
This function shall only be called from `autoscratch-triggers-alist'."
(interactive)
(let ((keys ()))
(dolist (e modelist)
(push (car e) keys))
(eval (cdr (assoc (completing-read "switch mode to: " keys) modelist)))))
;;;; Internal Functions ;;;; Internal Functions
(defun autoscratch--fork-and-rename-current () (defun autoscratch--fork-and-rename-current ()