aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Wiegley2004-05-08 13:04:29 +0000
committerJohn Wiegley2004-05-08 13:04:29 +0000
commitc4ae2d518c6d39f48a5b8dd15cd49498b55872a5 (patch)
tree0397bc61758bf31570c6d91ba6730ee88d8a511b
parent5d28fa0170785ecac4c2def426de4354b98869a1 (diff)
downloademacs-c4ae2d518c6d39f48a5b8dd15cd49498b55872a5.tar.gz
emacs-c4ae2d518c6d39f48a5b8dd15cd49498b55872a5.zip
2004-05-08 John Wiegley <johnw@newartisans.com>
* iswitchb.el (iswitchb-use-virtual-buffers): Added support for "virtual buffers" (off by default), which makes it possible to switch to the buffers of recently files. When a buffer name search fails, and this option is on, iswitchb will look at the list of recently visited files, and permit matching against those names. When the user hits RET on a match, it will revisit that file. (iswitchb-read-buffer): Added two optional arguments, which makes isearchb.el possible. (iswitchb-completions, iswitchb-set-matches, iswitchb-prev-match, iswitchb-next-match): Added support for virtual buffers.
-rw-r--r--lisp/ChangeLog44
-rw-r--r--lisp/iswitchb.el126
2 files changed, 144 insertions, 26 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 9db4ad63474..220f9abe206 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,47 @@
12004-05-08 John Wiegley <johnw@newartisans.com>
2
3 * iswitchb.el (iswitchb-use-virtual-buffers): Added support for
4 "virtual buffers" (off by default), which makes it possible to
5 switch to the "virtual" buffers of recently visited files. When a
6 buffer name search fails, and this option is on, iswitchb will
7 look at the list of recently visited files, and permit matching
8 against those names. When the user hits RET on a match, it will
9 revisit that file.
10 (iswitchb-read-buffer): Added two optional arguments, which makes
11 isearchb.el possible.
12 (iswitchb-completions, iswitchb-set-matches, iswitchb-prev-match,
13 iswitchb-next-match): Added support for virtual buffers.
14
15 * isearchb.el: This module extends iswitchb to provide "as you
16 type" buffer selection.
17
18 * textmodes/flyspell.el (flyspell-highlight-incorrect-region):
19 Ignore the read-only property when flyspell highlighting is on.
20 Not ignoring it leads to a series of confusing errors.
21 (flyspell-highlight-duplicate-region): Ignore read-only, as above,
22 but also make sure to call flyspell-incorrect-hook.
23 (flyspell-maybe-correct-transposition): Perform transposition test
24 by bit twiddling a string, rather than using a temp buffer.
25 (flyspell-maybe-correct-doubling): Use a string rather than a temp
26 buffer. This is also the original version of the code, which
27 could not be checked in before due to a previous lack of
28 assignment papers. This version has seen heavy usage on my system
29 for several years now.
30
31 * calendar/cal-bahai.el: New file, which adds support for the
32 Baha'i calendar to Emacs. This calendar is based on a solar year
33 of 19 months of 19 days, with 4 intercalary days. Each year
34 begins on March 21, with the calendar starting in 1844.
35
36 * calendar/cal-menu.el, calendar/calendar.el,
37 calendar/diary-lib.el, calendar/holidays.el: Added support for
38 using cal-bahai.el.
39
40 * eshell/em-glob.el (eshell-glob-initialize): Move initialization
41 of `eshell-glob-chars-regexp' into `eshell-glob-regexp', so that
42 function can be used outside of eshell buffers.
43 (eshell-glob-regexp): Initialize `eshell-glob-chars-regexp' here.
44
12004-05-08 Juanma Barranquero <lektu@terra.es> 452004-05-08 Juanma Barranquero <lektu@terra.es>
2 46
3 * help-fns.el (help-do-arg-highlight): Temporarily set ?\- to be a 47 * help-fns.el (help-do-arg-highlight): Temporarily set ?\- to be a
diff --git a/lisp/iswitchb.el b/lisp/iswitchb.el
index 7bada72310c..9b124848b18 100644
--- a/lisp/iswitchb.el
+++ b/lisp/iswitchb.el
@@ -307,6 +307,20 @@ multitude of buffers open."
307 :type '(choice (const :tag "Show all" nil) integer) 307 :type '(choice (const :tag "Show all" nil) integer)
308 :group 'iswitchb) 308 :group 'iswitchb)
309 309
310(defcustom iswitchb-use-virtual-buffers nil
311 "*If non-nil, refer to past buffers when none match.
312This feature relies upon the `recentf' package, which will be
313enabled if this variable is configured to a non-nil value."
314 :type 'boolean
315 :require 'recentf
316 :set (function
317 (lambda (sym value)
318 (recentf-mode value)
319 (set sym value)))
320 :group 'iswitchb)
321
322(defvar iswitchb-virtual-buffers nil)
323
310(defcustom iswitchb-cannot-complete-hook 'iswitchb-completion-help 324(defcustom iswitchb-cannot-complete-hook 'iswitchb-completion-help
311 "*Hook run when `iswitchb-complete' can't complete any more. 325 "*Hook run when `iswitchb-complete' can't complete any more.
312The most useful values are `iswitchb-completion-help', which pops up a 326The most useful values are `iswitchb-completion-help', which pops up a
@@ -571,12 +585,18 @@ in a separate window.
571 (iswitchb-possible-new-buffer buf))) 585 (iswitchb-possible-new-buffer buf)))
572 )))) 586 ))))
573 587
574(defun iswitchb-read-buffer (prompt &optional default require-match) 588(defun iswitchb-read-buffer (prompt &optional default require-match
589 start matches-set)
575 "Replacement for the built-in `read-buffer'. 590 "Replacement for the built-in `read-buffer'.
576Return the name of a buffer selected. 591Return the name of a buffer selected.
577PROMPT is the prompt to give to the user. DEFAULT if given is the default 592PROMPT is the prompt to give to the user.
578buffer to be selected, which will go to the front of the list. 593DEFAULT if given is the default buffer to be selected, which will
579If REQUIRE-MATCH is non-nil, an existing-buffer must be selected." 594go to the front of the list.
595If REQUIRE-MATCH is non-nil, an existing-buffer must be selected.
596If START is a string, the selection process is started with that
597string.
598If MATCHES-SET is non-nil, the buflist is not updated before
599the selection process begins. Used by isearchb.el."
580 (let 600 (let
581 ( 601 (
582 buf-sel 602 buf-sel
@@ -589,14 +609,15 @@ If REQUIRE-MATCH is non-nil, an existing-buffer must be selected."
589 609
590 (iswitchb-define-mode-map) 610 (iswitchb-define-mode-map)
591 (setq iswitchb-exit nil) 611 (setq iswitchb-exit nil)
592 (setq iswitchb-rescan t)
593 (setq iswitchb-text "")
594 (setq iswitchb-default 612 (setq iswitchb-default
595 (if (bufferp default) 613 (if (bufferp default)
596 (buffer-name default) 614 (buffer-name default)
597 default)) 615 default))
598 (iswitchb-make-buflist iswitchb-default) 616 (setq iswitchb-text (or start ""))
599 (iswitchb-set-matches) 617 (unless matches-set
618 (setq iswitchb-rescan t)
619 (iswitchb-make-buflist iswitchb-default)
620 (iswitchb-set-matches))
600 (let 621 (let
601 ((minibuffer-local-completion-map iswitchb-mode-map) 622 ((minibuffer-local-completion-map iswitchb-mode-map)
602 ;; Record the minibuffer depth that we expect to find once 623 ;; Record the minibuffer depth that we expect to find once
@@ -605,32 +626,41 @@ If REQUIRE-MATCH is non-nil, an existing-buffer must be selected."
605 (iswitchb-require-match require-match)) 626 (iswitchb-require-match require-match))
606 ;; prompt the user for the buffer name 627 ;; prompt the user for the buffer name
607 (setq iswitchb-final-text (completing-read 628 (setq iswitchb-final-text (completing-read
608 prompt ;the prompt 629 prompt ;the prompt
609 '(("dummy" . 1)) ;table 630 '(("dummy" . 1)) ;table
610 nil ;predicate 631 nil ;predicate
611 nil ;require-match [handled elsewhere] 632 nil ;require-match [handled elsewhere]
612 nil ;initial-contents 633 start ;initial-contents
613 'iswitchb-history))) 634 'iswitchb-history)))
614 (if (and (not (eq iswitchb-exit 'usefirst)) 635 (if (and (not (eq iswitchb-exit 'usefirst))
615 (get-buffer iswitchb-final-text)) 636 (get-buffer iswitchb-final-text))
616 ;; This happens for example if the buffer was chosen with the mouse. 637 ;; This happens for example if the buffer was chosen with the mouse.
617 (setq iswitchb-matches (list iswitchb-final-text))) 638 (setq iswitchb-matches (list iswitchb-final-text)
639 iswitchb-virtual-buffers nil))
640
641 ;; If no buffer matched, but a virtual buffer was selected, visit
642 ;; that file now and act as though that buffer had been selected.
643 (if (and iswitchb-virtual-buffers
644 (not (iswitchb-existing-buffer-p)))
645 (let ((virt (car iswitchb-virtual-buffers)))
646 (find-file-noselect (cdr virt))
647 (setq iswitchb-matches (list (car virt))
648 iswitchb-virtual-buffers nil)))
618 649
619 ;; Handling the require-match must be done in a better way. 650 ;; Handling the require-match must be done in a better way.
620 (if (and require-match (not (iswitchb-existing-buffer-p))) 651 (if (and require-match
652 (not (iswitchb-existing-buffer-p)))
621 (error "Must specify valid buffer")) 653 (error "Must specify valid buffer"))
622 654
623 (if (or 655 (if (or (eq iswitchb-exit 'takeprompt)
624 (eq iswitchb-exit 'takeprompt) 656 (null iswitchb-matches))
625 (null iswitchb-matches))
626 (setq buf-sel iswitchb-final-text) 657 (setq buf-sel iswitchb-final-text)
627 ;; else take head of list 658 ;; else take head of list
628 (setq buf-sel (car iswitchb-matches))) 659 (setq buf-sel (car iswitchb-matches)))
629 660
630 ;; Or possibly choose the default buffer 661 ;; Or possibly choose the default buffer
631 (if (equal iswitchb-final-text "") 662 (if (equal iswitchb-final-text "")
632 (setq buf-sel 663 (setq buf-sel (car iswitchb-matches)))
633 (car iswitchb-matches)))
634 664
635 buf-sel)) 665 buf-sel))
636 666
@@ -731,18 +761,29 @@ If no buffer exactly matching the prompt exists, maybe create a new one."
731 (setq iswitchb-exit 'findfile) 761 (setq iswitchb-exit 'findfile)
732 (exit-minibuffer)) 762 (exit-minibuffer))
733 763
764(eval-when-compile
765 (defvar recentf-list))
766
734(defun iswitchb-next-match () 767(defun iswitchb-next-match ()
735 "Put first element of `iswitchb-matches' at the end of the list." 768 "Put first element of `iswitchb-matches' at the end of the list."
736 (interactive) 769 (interactive)
737 (let ((next (cadr iswitchb-matches))) 770 (let ((next (cadr iswitchb-matches)))
738 (setq iswitchb-buflist (iswitchb-chop iswitchb-buflist next)) 771 (if (and (null next) iswitchb-virtual-buffers)
772 (setq recentf-list
773 (iswitchb-chop recentf-list
774 (cdr (cadr iswitchb-virtual-buffers))))
775 (setq iswitchb-buflist (iswitchb-chop iswitchb-buflist next)))
739 (setq iswitchb-rescan t))) 776 (setq iswitchb-rescan t)))
740 777
741(defun iswitchb-prev-match () 778(defun iswitchb-prev-match ()
742 "Put last element of `iswitchb-matches' at the front of the list." 779 "Put last element of `iswitchb-matches' at the front of the list."
743 (interactive) 780 (interactive)
744 (let ((prev (car (last iswitchb-matches)))) 781 (let ((prev (car (last iswitchb-matches))))
745 (setq iswitchb-buflist (iswitchb-chop iswitchb-buflist prev)) 782 (if (and (null prev) iswitchb-virtual-buffers)
783 (setq recentf-list
784 (iswitchb-chop recentf-list
785 (cdr (car (last iswitchb-virtual-buffers)))))
786 (setq iswitchb-buflist (iswitchb-chop iswitchb-buflist prev)))
746 (setq iswitchb-rescan t))) 787 (setq iswitchb-rescan t)))
747 788
748(defun iswitchb-chop (list elem) 789(defun iswitchb-chop (list elem)
@@ -834,7 +875,8 @@ current frame, rather than all frames, regardless of value of
834 (setq iswitchb-matches 875 (setq iswitchb-matches
835 (let* ((buflist iswitchb-buflist)) 876 (let* ((buflist iswitchb-buflist))
836 (iswitchb-get-matched-buffers iswitchb-text iswitchb-regexp 877 (iswitchb-get-matched-buffers iswitchb-text iswitchb-regexp
837 buflist))))) 878 buflist))
879 iswitchb-virtual-buffers nil)))
838 880
839(defun iswitchb-get-matched-buffers (regexp 881(defun iswitchb-get-matched-buffers (regexp
840 &optional string-format buffer-list) 882 &optional string-format buffer-list)
@@ -1188,6 +1230,10 @@ Copied from `icomplete-exhibit' with two changes:
1188 contents 1230 contents
1189 (not minibuffer-completion-confirm))))))) 1231 (not minibuffer-completion-confirm)))))))
1190 1232
1233(eval-when-compile
1234 (defvar most-len)
1235 (defvar most-is-exact))
1236
1191(defun iswitchb-output-completion (com) 1237(defun iswitchb-output-completion (com)
1192 (if (= (length com) most-len) 1238 (if (= (length com) most-len)
1193 ;; Most is one exact match, 1239 ;; Most is one exact match,
@@ -1221,6 +1267,35 @@ Modified from `icomplete-completions'."
1221 first) 1267 first)
1222 (setq comps (cons first (cdr comps))))) 1268 (setq comps (cons first (cdr comps)))))
1223 1269
1270 ;; If no buffers matched, and virtual buffers are being used, then
1271 ;; consult the list of past visited files, to see if we can find
1272 ;; the file which the user might thought was still open.
1273 (when (and iswitchb-use-virtual-buffers (null comps)
1274 recentf-list)
1275 (setq iswitchb-virtual-buffers nil)
1276 (let ((head recentf-list) name)
1277 (while head
1278 (if (and (setq name (file-name-nondirectory (car head)))
1279 (string-match (if iswitchb-regexp
1280 iswitchb-text
1281 (regexp-quote iswitchb-text)) name)
1282 (null (get-file-buffer (car head)))
1283 (not (assoc name iswitchb-virtual-buffers))
1284 (not (iswitchb-ignore-buffername-p name))
1285 (file-exists-p (car head)))
1286 (setq iswitchb-virtual-buffers
1287 (cons (cons name (car head))
1288 iswitchb-virtual-buffers)))
1289 (setq head (cdr head)))
1290 (setq iswitchb-virtual-buffers (nreverse iswitchb-virtual-buffers)
1291 comps (mapcar 'car iswitchb-virtual-buffers))
1292 (let ((comp comps))
1293 (while comp
1294 (put-text-property 0 (length (car comp))
1295 'face 'font-lock-builtin-face
1296 (car comp))
1297 (setq comp (cdr comp))))))
1298
1224 (cond ((null comps) (format " %sNo match%s" 1299 (cond ((null comps) (format " %sNo match%s"
1225 open-bracket-determined 1300 open-bracket-determined
1226 close-bracket-determined)) 1301 close-bracket-determined))
@@ -1255,10 +1330,9 @@ Modified from `icomplete-completions'."
1255 (most nil) 1330 (most nil)
1256 (most-len (length most)) 1331 (most-len (length most))
1257 most-is-exact 1332 most-is-exact
1258 (alternatives (if most 1333 (alternatives
1259 (mapconcat 'iswitchb-output-completion 1334 (mapconcat (if most 'iswitchb-output-completion
1260 comps ",") 1335 'identity) comps ",")))
1261 (mapconcat 'identity comps ","))))
1262 1336
1263 (concat 1337 (concat
1264 1338