Skip to content
Browse files

Filter unwanted commands from the smex prompt

Removing:
   obsolete commands
   advice forms
   menu-bar commands
   mouse-interactive commands (imperfect, but no false positives)
Adding the ability to mark a command to be filtered from the
prompt by setting the 'smex-ignore property.
  • Loading branch information...
1 parent 6a4c512 commit f21e593022fe7968b5b821a04a012730d546125d @rolandwalker committed
Showing with 28 additions and 1 deletion.
  1. +28 −1 smex.el
View
29 smex.el
@@ -174,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'"

0 comments on commit f21e593

Please sign in to comment.
Something went wrong with that request. Please try again.