home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / alt / lucidem / help / 343 < prev    next >
Encoding:
Text File  |  1992-08-27  |  7.7 KB  |  194 lines

  1. Newsgroups: alt.lucid-emacs.help
  2. Path: sparky!uunet!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!m2.dseg.ti.com!lystad
  3. From: lystad@m2.dseg.ti.com (Garr Lystad)
  4. Subject: Re: Mouse enhancements for buffer-menu mode
  5. Organization: TI DSEG, Spring Creek, Plano, Tx.
  6. In-Reply-To: c23mts@kocrsv01.delcoelect.com's message of 26 Aug 92 16:58:53 GMT
  7. References: <1992Aug26.165853.22947@kocrsv01.delcoelect.com>
  8. Message-ID: <LYSTAD.92Aug27090446@m2.dseg.ti.com>
  9. Reply-To: Garr Lystad <lystad@m2.dseg.ti.com>
  10. Sender: lystad@m2.dseg.ti.com (Garr Lystad)
  11. Date: Thu, 27 Aug 1992 15:04:46 GMT
  12. Lines: 180
  13.  
  14. In article <1992Aug26.165853.22947@kocrsv01.delcoelect.com> c23mts@kocrsv01.delcoelect.com (Mike Scheidler) writes:
  15.  
  16.  
  17. >   Here are a couple of mouse-based functions I use with buffer menu mode.
  18. >   They're not elegant or complicated, but they make my life a little easier.
  19. >   ....
  20.  
  21. I too have made some functions for buffer-menu-mode.  Mine are not
  22. elegant or complicated either, but they offer a couple of other
  23. options.
  24.  
  25. The commands and key settings are as follows:
  26. (local-set-key '(shift button1) 'mouse-select-buffer-1-window)
  27. (local-set-key '(shift button2) 'mouse-select-buffer-this-window)
  28. (local-set-key '(shift button3) 'mouse-select-buffer-other-window) )))
  29. (local-set-key '(button2) 'mouse-select-buffer-this-window)
  30. (local-set-key '(button3) 'mouse-select-buffer-other-window)
  31. (define-key global-map "\C-c\C-b" 'list-buffers-1-window)
  32.  
  33. I don't use multiple screens, so I don't have something for that, as
  34. Mike does.  
  35.  
  36. Since I often have a lot of buffers, I have added a command to put the
  37. buffer list in one window, the last command above.
  38.  
  39. I have also altered list-buffers, as commented in the code below, so
  40. that an argument of 2 will list only modified file buffers (handy in
  41. the middle of various tags operations) and an argument of 3 will list
  42. only dired mode buffers.  An argument of anything else, as previously,
  43. will list all file buffers only.
  44.  
  45. In case you are wondering why the macro is written without backquotes,
  46. etc., it was for practice.  I remember finding a bug in the backquote
  47. package a year or more ago with Emacs 18.58 and was thinking about
  48. repairs.  Then I got to use a Lisp machine again and now I've
  49. forgotten what the bug was.  Does anyone know of anything wrong with
  50. backquotes or anything that has been fixed since that Emacs?
  51.  
  52.  
  53. ;;;; modifications to list buffers, and eval-in-buffer macro used there
  54.  
  55. ;; Taken from the file sun-mouse.el
  56. (defmacro  (buffer &rest forms)
  57.   "Macro to switches to BUFFER, evaluates FORMS, returns to original buffer."
  58.   ;; When you don't need the complete window context of eval-in-window
  59.   (nconc (list 'let)
  60.      (list '((start-buffer (current-buffer))))
  61.      (list (nconc (list 'unwind-protect)
  62.               (list (nconc (list 'progn)
  63.                    (list (list 'set-buffer buffer))
  64.                    forms))
  65.               (list '(set-buffer start-buffer)) ))) )
  66.  
  67. (put 'eval-in-buffer 'lisp-indent-hook 1)
  68.  
  69. (defun goto-event-char (event)
  70.   "Arglist: (event). Move point to the mouse-click."
  71.   (let ((event-buffer (window-buffer (event-window event))))
  72.     (if (eql (current-buffer) event-buffer)  
  73.     (switch-to-buffer event-buffer)
  74.       (switch-to-buffer-other-window event-buffer) )
  75.     (if (event-point event) (goto-char (event-point event))) ))
  76.  
  77. (defun mouse-select-buffer-1-window (event)
  78.   "Select this line's buffer, alone, in full screen."
  79.   (interactive "e")
  80.   (goto-event-char event)
  81.   (Buffer-menu-1-window) )
  82.  
  83. (defun mouse-select-buffer-other-window (event)
  84.   "Select this line's buffer, alone, in other window."
  85.   (interactive "e")
  86.   (goto-event-char event)
  87.   (Buffer-menu-other-window) )
  88.  
  89. (defun mouse-select-buffer-this-window (event)
  90.   "Select this line's buffer, alone, in this window."
  91.   (interactive "e")
  92.   (goto-event-char event)
  93.   (Buffer-menu-this-window) )
  94.  
  95. ;;; for buffer-menu-mode
  96.  
  97. (defun install-buffer-list-map ()
  98.   (let ((buffer (get-buffer "*Buffer List*")))
  99.     (eval-in-buffer buffer
  100.       (local-set-key '(shift button1) 'mouse-select-buffer-1-window)
  101.       (local-set-key '(shift button2) 'mouse-select-buffer-this-window)
  102.       (local-set-key '(button2) 'mouse-select-buffer-this-window)
  103.       (local-set-key '(button3) 'mouse-select-buffer-other-window)
  104.       (local-set-key '(shift button3) 'mouse-select-buffer-other-window) )))
  105.  
  106.  
  107. (install-buffer-list-map)
  108.  
  109. (defun list-buffers-1-window (files)
  110.   (interactive "P")
  111.   (list-buffers files)
  112.   (switch-to-buffer (get-buffer "*Buffer List*"))
  113.   (delete-other-windows)
  114.   )
  115.  
  116. (define-key global-map "\C-c\C-b" 'list-buffers-1-window)
  117.  
  118. (defun list-buffers (&optional files-only)
  119.   "Display a list of names of existing buffers.
  120. Inserts it in buffer *Buffer List* and displays that.
  121. Note that buffers with names starting with spaces are omitted.
  122. Non-null optional arg FILES-ONLY means mention only file buffers.
  123.   If FILES-ONLY has the special value 2, then only modified file buffers are listed.
  124.   If FILES-ONLY has the special value 3, then only dired buffers are listed.
  125.  
  126. The M column contains a * for buffers that are modified.
  127. The R column contains a % for buffers that are read-only."
  128.   (interactive "P")
  129.   (let ((current (current-buffer))
  130.     (col1 19)
  131.     output)
  132.     (save-excursion
  133.       (with-output-to-temp-buffer "*Buffer List*"
  134.         (let ((buffers (buffer-list)))
  135.           (setq output standard-output)
  136.           (set-buffer output)
  137.           (Buffer-menu-mode)
  138.           (setq buffer-read-only nil)
  139.           (buffer-disable-undo output)
  140.           (insert list-buffers-header-line)
  141.           (while buffers
  142.             (let* ((buffer (car buffers))
  143.                    (name (buffer-name buffer))
  144.                    (file (buffer-file-name buffer)))
  145.               (setq buffers (cdr buffers))
  146.               (cond ((null name)) ;deleted buffer
  147.                     ((and (/= 0 (length name));don't mention if starts with " "
  148.                           (= (aref name 0) ?\ )))
  149.                     ((and files-only (null file)
  150.               (not (eql files-only 3))))                            ;; gsl 8-20-92
  151.             ((and (eql files-only 2) (not (buffer-modified-p buffer)))) ;; gsl 8-20-92
  152.             ((and (eql files-only 3)                                    ;; gsl 8-20-92
  153.               (not (eql 'dired-mode                                 ;; gsl 8-20-92
  154.                     (eval-in-buffer buffer major-mode))) ))     ;; gsl 8-20-92
  155.                     (t
  156.                      (set-buffer buffer)
  157.                      (let ((ro buffer-read-only)
  158.                            (id list-buffers-identification))
  159.                        (set-buffer output)
  160.                        (insert (if (eq buffer current)
  161.                                    (progn (setq current (point)) ?\.)
  162.                                    ?\ ))
  163.                (insert (if (buffer-modified-p buffer)
  164.                                    ?\* 
  165.                    ?\ ))
  166.                (insert (if ro
  167.                                    ?\%
  168.                                    ?\ ))
  169.                        (if (string-match "[\n\"\\ \t]" name)
  170.                            (let ((print-escape-newlines t))
  171.                              (prin1 name output))
  172.                            (insert ?\  name))
  173.                        (indent-to col1 1)
  174.                        (cond ((stringp id)
  175.                               (insert id))
  176.                              (id
  177.                               (set-buffer buffer)
  178.                               (condition-case e
  179.                                   (funcall id output)
  180.                                 (error
  181.                                  (princ "***" output) (prin1 e output)))
  182.                               (set-buffer output)
  183.                               (goto-char (point-max)))))
  184.                      (insert ?\n)))))
  185.           (setq buffer-read-only t))))
  186.     (if (not (bufferp current))
  187.     (save-excursion
  188.       (set-buffer output)
  189.       (goto-char current)))))
  190.  
  191. ;;------------------------------------- end of file
  192.  
  193.   --  Garr
  194.