Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use customize to simplify startup #12

Open
wants to merge 5 commits into from

2 participants

@haxney

By using define-minor-mode with an autoload cookie, smex can be loaded and initialized purely through Customize.

The old smex-initialize function has been removed, as its functionality is handled entirely within smex-mode.

This resolves issue #11

haxney added some commits
@haxney haxney Add the minor mode `smex-mode'
Sets up the keymap for smex and can be set through `customize'. This can be used
instead of `smex-initialize'.
7cf2a15
@haxney haxney Fix keymap format for `smex-major-mode-commands'
`[M-X]' just gets translated to "M-x"; to get the intended effect of "M-X", the
format is `[?\M-X]'
f6fc9b4
@haxney haxney Modify docstrings to fit standard Emacs style.
The custom variables `smex-save-file' and `smex-history-length' no longer need
to be set early on. Initialization only takes place when `smex-mode' is turned
on, so those variables are read at that point (which is after customize has read
the values).
249d97f
@haxney haxney Remove `smex-initialize' and `smex-initialize-ido'.
Their functionality is handled by `smex-mode'.
0cf05be
@haxney haxney Clean up when `smex-mode' is disabled. bed1ed0
@asmeurer

You should maybe keep smex-initialize for backwards compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 3, 2012
  1. @haxney

    Add the minor mode `smex-mode'

    haxney authored
    Sets up the keymap for smex and can be set through `customize'. This can be used
    instead of `smex-initialize'.
Commits on May 4, 2012
  1. @haxney

    Fix keymap format for `smex-major-mode-commands'

    haxney authored
    `[M-X]' just gets translated to "M-x"; to get the intended effect of "M-X", the
    format is `[?\M-X]'
  2. @haxney

    Modify docstrings to fit standard Emacs style.

    haxney authored
    The custom variables `smex-save-file' and `smex-history-length' no longer need
    to be set early on. Initialization only takes place when `smex-mode' is turned
    on, so those variables are read at that point (which is after customize has read
    the values).
  3. @haxney

    Remove `smex-initialize' and `smex-initialize-ido'.

    haxney authored
    Their functionality is handled by `smex-mode'.
  4. @haxney
This page is out of date. Refresh to see the latest.
Showing with 47 additions and 37 deletions.
  1. +47 −37 smex.el
View
84 smex.el
@@ -15,11 +15,12 @@
;;; Commentary:
-;; Quick start:
-;; run (smex-initialize)
+;; Smex is a global minor mode which replaces `execute-extended-command' with
+;; `smex', which uses `ido-mode' to provide enhanced completion.
;;
-;; Bind the following commands:
-;; smex, smex-major-mode-commands
+;; To enable, set the custom variable `smex-mode' to a non-nil value.
+;;
+;; Smex can also be enabled manually by executing the function `smex-mode'.
;;
;; For a detailed introduction see:
;; http://github.com/nonsequitur/smex/blob/master/README.markdown
@@ -35,25 +36,23 @@
:group 'extensions
:group 'convenience
:version "1.1"
+ :prefix "smex-"
:link '(emacs-library-link :tag "Lisp File" "smex.el"))
(defcustom smex-auto-update t
- "If non-nil, `Smex' checks for new commands each time it is run.
+ "If non-nil, `smex' checks for new commands each time it is run.
Turn it off for minor speed improvements on older systems."
:type 'boolean
:group 'smex)
(defcustom smex-save-file "~/.smex-items"
"File in which the smex state is saved between Emacs sessions.
-Variables stored are: `smex-data', `smex-history'.
-Must be set before initializing Smex."
- :type 'string
+Variables stored are: `smex-data', `smex-history'."
+ :type 'file
:group 'smex)
(defcustom smex-history-length 7
- "Determines on how many recently executed commands
-Smex should keep a record.
-Must be set before initializing Smex."
+ "Number of recently executed commands Smex records."
:type 'integer
:group 'smex)
@@ -63,13 +62,12 @@ Must be set before initializing Smex."
:group 'smex)
(defcustom smex-key-advice-ignore-menu-bar nil
- "If non-nil, `smex-key-advice' ignores `menu-bar' bindings"
+ "If non-nil, `smex-key-advice' ignores `menu-bar' bindings."
:type 'boolean
:group 'smex)
(defcustom smex-flex-matching t
- "Enables Ido flex matching. On by default.
-Set this to nil to disable fuzzy matching."
+ "Non-nil means enable Ido flex matching."
:type 'boolean
:group 'smex)
@@ -83,7 +81,40 @@ Set this to nil to disable fuzzy matching."
;;--------------------------------------------------------------------------------
;; Smex Interface
+;;;###autoload
+(define-minor-mode smex-mode "Minor mode to supercharge M-x.
+When `smex-mode' is active, `execute-extended-command' is
+remapped to `smex'. Built on top of Ido, it provides a convenient
+interface to your recently and most frequently used commands. And
+to all the other commands, too.
+
+No longer supports legacy save files; if you are still using the
+old-style save file (\"~/smex.save\"), you will need to copy it
+to the location in `smex-save-file'."
+ :group 'smex
+ :global t
+ :require 'smex
+ :keymap '(([remap execute-extended-command] . smex)
+ ([?\M-X] . smex-major-mode-commands))
+ (if smex-mode
+ (progn
+ (unless ido-mode (ido-common-initialization))
+ (let ((save-file (expand-file-name smex-save-file)))
+ (if (file-readable-p save-file)
+ (with-temp-buffer
+ (insert-file-contents save-file)
+ (setq smex-history (read (current-buffer))
+ smex-data (read (current-buffer))))
+ (setq smex-history nil
+ smex-data nil))
+ (smex-detect-new-commands)
+ (smex-rebuild-cache)
+ (add-hook 'kill-emacs-hook 'smex-save-to-file))))
+ (smex-save-to-file)
+ (remove-hook 'kill-emacs-hook 'smex-save-to-file))
+
(defun smex ()
+ "Read a function name using ido-enhanced search and call it."
(interactive)
(if (smex-already-running)
(smex-update-and-rerun)
@@ -227,27 +258,6 @@ This function provides temporary means to aid the transition."
smex-save-file legacy-save-file))
(setq smex-save-file legacy-save-file)))))
-;;;###autoload
-(defun smex-initialize ()
- (interactive)
- (unless ido-mode (smex-initialize-ido))
- (smex-detect-legacy-save-file)
- (let ((save-file (expand-file-name smex-save-file)))
- (if (file-readable-p save-file)
- (with-temp-buffer
- (insert-file-contents save-file)
- (setq smex-history (read (current-buffer))
- smex-data (read (current-buffer))))
- (setq smex-history nil smex-data nil))
- (smex-detect-new-commands)
- (smex-rebuild-cache)
- (add-hook 'kill-emacs-hook 'smex-save-to-file)))
-
-(defun smex-initialize-ido ()
- "Sets up a minimal Ido environment for `ido-completing-read'."
- (ido-init-completion-maps)
- (add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup))
-
(defun smex-save-history ()
"Updates `smex-history'"
(setq smex-history nil)
@@ -436,13 +446,13 @@ Returns nil when reaching the end of the list."
(let ((library-path (symbol-file mode))
(mode-name (symbol-name mode))
commands)
-
+
(string-match "\\(.+?\\)\\(-mode\\)?$" mode-name)
;; 'lisp-mode' -> 'lisp'
(setq mode-name (match-string 1 mode-name))
(if (string= mode-name "c") (setq mode-name "cc"))
(setq mode-name (regexp-quote mode-name))
-
+
(dolist (feature load-history)
(let ((feature-path (car feature)))
(when (and feature-path (or (equal feature-path library-path)
Something went wrong with that request. Please try again.