Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out unwanted commands from smex completions #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion smex.el
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Set this to nil to disable fuzzy matching."
(funcall action chosen-item))
(unwind-protect
(progn (setq prefix-arg current-prefix-arg)
(setq this-command chosen-item)
(command-execute chosen-item 'record))
(smex-rank chosen-item)
(smex-show-key-advice chosen-item)
Expand Down Expand Up @@ -173,7 +174,34 @@ Set this to nil to disable fuzzy matching."
(setq smex-ido-cache (smex-convert-for-ido smex-cache)))

(defun smex-convert-for-ido (command-items)
(mapcar (lambda (command-item) (symbol-name (car command-item))) command-items))
(delq nil (mapcar #'(lambda (command-item)
(let ((command-sym (car command-item))
(command-str (symbol-name (car command-item))))
(if (and command-sym
(or (get command-sym 'smex-ignore) ; request to be ignored
(get command-sym 'byte-obsolete-info) ; marked obsolete
(string-match-p "\\`ad-Orig-" command-str) ; there is also an advised form with true name
(string-match-p "\\`menu-bar-" command-str) ; menu-bar are likely duplicates
(and (listp (help-function-arglist command-sym)) ; mouse-interactive, roughly
(not (eq ?\& (aref (symbol-name (car (help-function-arglist command-sym))) 0)))
(stringp (cadr (interactive-form command-sym)))
(string-match-p "\\`[*@^]*e" (cadr (interactive-form command-sym))))))
nil
;; else
command-str)))
command-items)))

(defun smex-ignore (commands)
"Tell smex to ignore the list of symbols in COMMANDS.

Ignored commands are still usable, but are hidden from completion
in smex.

If COMMANDS is a single symbol, it will be coerced to a list."
(when (symbolp commands)
(setq commands (list commands)))
(dolist (sym commands)
(put sym 'smex-ignore t)))

(defun smex-restore-history ()
"Rearranges `smex-cache' according to `smex-history'"
Expand Down