|
1 | | -;;; smex.el --- M-x interface with Ido-style fuzzy matching. |
| 1 | +;;; smex.el --- M-x interface with Ido-style fuzzy matching. -*- lexical-binding: t; -*- |
2 | 2 |
|
3 | 3 | ;; Copyright (C) 2009-2014 Cornelius Mika and contributors |
4 | 4 | ;; |
@@ -268,17 +268,20 @@ Set this to nil to disable fuzzy matching." |
268 | 268 | "Updates `smex-history'" |
269 | 269 | (setq smex-history nil) |
270 | 270 | (let ((cell smex-cache)) |
271 | | - (dotimes (i smex-history-length) |
| 271 | + (dotimes (_ smex-history-length) |
272 | 272 | (setq smex-history (cons (caar cell) smex-history)) |
273 | 273 | (setq cell (cdr cell)))) |
274 | 274 | (setq smex-history (nreverse smex-history))) |
275 | 275 |
|
| 276 | +(defmacro smex-pp (list-var) |
| 277 | + `(smex-pp* ,list-var ,(symbol-name list-var))) |
| 278 | + |
276 | 279 | (defun smex-save-to-file () |
277 | 280 | (interactive) |
278 | 281 | (smex-save-history) |
279 | 282 | (with-temp-file (expand-file-name smex-save-file) |
280 | | - (ido-pp 'smex-history) |
281 | | - (ido-pp 'smex-data))) |
| 283 | + (smex-pp smex-history) |
| 284 | + (smex-pp smex-data))) |
282 | 285 |
|
283 | 286 | ;;-------------------------------------------------------------------------------- |
284 | 287 | ;; Ranking |
@@ -340,8 +343,7 @@ Set this to nil to disable fuzzy matching." |
340 | 343 | (defun smex-sort-item-at (n) |
341 | 344 | "Sorts item at position N in `smex-cache'." |
342 | 345 | (let* ((command-cell (nthcdr n smex-cache)) |
343 | | - (command-item (car command-cell)) |
344 | | - (command-count (cdr command-item))) |
| 346 | + (command-item (car command-cell))) |
345 | 347 | (let ((insert-at (smex-detect-position |
346 | 348 | command-cell |
347 | 349 | (lambda (cell) |
@@ -412,7 +414,7 @@ Returns nil when reaching the end of the list." |
412 | 414 | commands)) |
413 | 415 |
|
414 | 416 | (defun smex-parse-keymap (map commands) |
415 | | - (map-keymap (lambda (binding element) |
| 417 | + (map-keymap (lambda (_binding element) |
416 | 418 | (if (and (listp element) (eq 'keymap (car element))) |
417 | 419 | (smex-parse-keymap element commands) |
418 | 420 | ;; Strings are commands, too. Reject them. |
@@ -457,9 +459,25 @@ sorted by frequency of use." |
457 | 459 | (setq buffer-read-only t) |
458 | 460 | (let ((inhibit-read-only t)) |
459 | 461 | (erase-buffer) |
460 | | - (ido-pp 'unbound-commands)) |
| 462 | + (smex-pp unbound-commands)) |
461 | 463 | (set-buffer-modified-p nil) |
462 | 464 | (goto-char (point-min)))) |
463 | 465 |
|
| 466 | +;; A copy of `ido-pp' that's compatible with lexical bindings |
| 467 | +(defun smex-pp* (list list-name) |
| 468 | + (let ((print-level nil) (eval-expression-print-level nil) |
| 469 | + (print-length nil) (eval-expression-print-length nil)) |
| 470 | + (insert "\n;; ----- " list-name " -----\n(\n ") |
| 471 | + (while list |
| 472 | + (let* ((elt (car list)) |
| 473 | + (s (if (consp elt) (car elt) elt))) |
| 474 | + (if (and (stringp s) (= (length s) 0)) |
| 475 | + (setq s nil)) |
| 476 | + (if s |
| 477 | + (prin1 elt (current-buffer))) |
| 478 | + (if (and (setq list (cdr list)) s) |
| 479 | + (insert "\n ")))) |
| 480 | + (insert "\n)\n"))) |
| 481 | + |
464 | 482 | (provide 'smex) |
465 | 483 | ;;; smex.el ends here |
0 commit comments