Article View: fj.editor.emacs
Article #3294browse-yank.el (Re: How to utilize Emacs well sans effort. #2)
From: Noriya KOBAYASHI
Date: Thu, 20 Feb 1992 12:05
Date: Thu, 20 Feb 1992 12:05
468 lines
17854 bytes
17854 bytes
$@:eBg$N8ENS$G$9!#Ld$$9g$o$;$,B?$$$N$G!"(Jbrowse-yank.el $@$rG[I[$7$F$*$-$^(J
$@$9!#(J
ftp.ics.osaka-u.ac.jp:/elisp/library/section/useful-commands/browse-yank.el.Z
$@$K$"$j$^$9$N$G!"(Janon ftp $@$G$-$kJ}$O$3$A$i$G$b$I$&$>!#(J
$@#1#9F|$K:G=*;nLd$,=*$C$F!"$b$C$H;~4V(J$@$,$H$l$k$H4|BT$7$F$$$?$N$G$9$,!"$d(J
$@$i$J$$$H$$$1$J$$$3$H!"$d$j$?$$$3$H!"$,Bt;3$"$C$F!"$3$C$A$N$[$&CY$l(J$@$F$$(J
$@$^$9!#(J
--
$@8ENS(J $@5*:H(J ($@$3$P$d$7(J $@$N$j$d(J) E-mail: nk@ics.osaka-u.ac.jp
$@Bg:eBg3XBg3X1!(J $@4pAC9)3X8&5f(J$@2J(J ($@>pJs9)3XJ,Ln(J)
$@")(J560 $@Bg:eI\K-Cf;TBT7s;3D.#1HV#19f(J
----------------- $@@Z$j<h$j$;$s(J-------------------------
#!/bin/sh
# shar: Shell Archiver (v1.22)
#
# Run the following text with /bin/sh to create:
# browse-yank.el
#
if test -f browse-yank.el; then echo "File browse-yank.el exists"; else
echo "x - extracting browse-yank.el (Text)"
sed 's/^X//' << 'SHAR_EOF' > browse-yank.el &&
X;From mende@athos.rutgers.edu Mon Oct 3 14:20:43 1988
X;From: mende@athos.rutgers.edu (Bob Mende Pie)
X;Newsgroups: gnu.emacs,comp.emacs
X;Subject: Kill-Ring-Browser browse-yank.el
X;Keywords: here it is...
X;Date: 27 Sep 88 17:39:52 GMT
X;Organization: Yows `R' us
X;
X;
X; I have received a lot of requests for my kill-ring-browser, so I will
X;post it here... Please mail me all comments and suggestions. Also, rms
X;pointed out that there is the yank-pop command (which is M-y by default...
X;I bind browse-yank to M-y). yank-pop acts can act as a kill-ring-browser,
X;but it can be confusing as well.
X
X;; browse-yank.el
X;;
X;; A major mode for the browsing, editing, and selectively inserting
X;; elements of the kill-ring.
X;;
X;; Written by Robert Mende mende@rutgers.edu
X;; send all bugs/suggestions to author
X;; suggested binding: M-y
X
X;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
X;; This file is not officialy part of GNU Emacs.
X;; GNU Emacs is distributed in the hope that it will be useful,
X;; but WITHOUT ANY WARRANTY. No author or distributor
X;; accepts responsibility to anyone for the consequences of using it
X;; or for whether it serves any particular purpose or works at all,
X;; unless he says so in writing. Refer to the GNU Emacs General Public
X;; License for full details.
X
X;; Everyone is granted permission to copy, modify and redistribute
X;; GNU Emacs, but only under the conditions described in the
X;; GNU Emacs General Public License. A copy of this license is
X;; supposed to have been given to you along with GNU Emacs so you
X;; can know your rights and responsibilities. It should be in a
X;; file named COPYING. Among other things, the copyright notice
X;; and this notice must be preserved on all copies.
X
X
X(defmacro for (i lb ub &rest body)
X"Iterative \"for\" loop, in the form (for I LB UB BODY). I is locally
Xset to each number between LB and UB inclusive. Boundary points LB
Xand UB evaluated once. BODY not evaluated if boundary test fails.
XReturns nil."
X
X (list 'let (list (list i lb)
X (list '__%__UB__%__ ub))
X (append (list 'while (list '<= i '__%__UB__%__))
X body
X (list (list 'setq i (list '1+ i))))))
X
X
X(defvar browse-yank-buffer "*Browse Yank*"
X "name of the buffer in which the kill-ring is browsed.")
X
X(defvar browse-yank-barf-message "Can't browse-yank an empty kill-ring."
X "Error message displayed when an attempt is made to browse an empty
Xkill-ring. Raison d'etre stems from the ludicrous jests poked at the
Xcommand's name by people much less mature than you and I.")
X
X(defvar browse-yank-height 5
X "number of lines in the browse-yank window")
X
X(defvar browse-yank-inserted-p nil)
X
X(defvar browse-yank-orig-window-config nil
X "Window configuration prior to splitting off the browse-yank window.")
X
X(defvar browse-yank-cur 0
X"The ordinal position in the kill-ring, starting from the most recent
Xkill (position 1).")
X
X(defvar browse-yank-cur-txt "0"
X "As browse-yank-cur, but a string suitable for display in the
Xmode-line.")
X
X(defvar browse-yank-max 0
X"The ordinal position of the last element of the kill-ring.")
X
X(defvar browse-yank-max-txt "0"
X"As browse-yank-max, but a string suitable for display in the
Xmode-line.")
X
X
X(defvar browse-yank-mode-map (make-sparse-keymap)
X "the keymap in used in browse-yank-mode.")
X(define-key browse-yank-mode-map "\C-g" 'browse-yank-abort)
X(define-key browse-yank-mode-map "\C-x\C-m" 'browse-yank-insert)
X(define-key browse-yank-mode-map "?" 'describe-mode)
X(define-key browse-yank-mode-map ">" 'browse-yank-goto-last)
X(define-key browse-yank-mode-map "<" 'browse-yank-goto-first)
X(define-key browse-yank-mode-map "s" 'browse-yank-search-forward)
X(define-key browse-yank-mode-map "r" 'browse-yank-search-backward)
X(define-key browse-yank-mode-map "q" 'browse-yank-quit)
X(define-key browse-yank-mode-map "p" 'browse-yank-previous-yank)
X(define-key browse-yank-mode-map "n" 'browse-yank-next-yank)
X(define-key browse-yank-mode-map "m" 'browse-yank-yanks-saved)
X(define-key browse-yank-mode-map "l" 'browse-yank-locate-regexp)
X(define-key browse-yank-mode-map "j" 'browse-yank-goto-yank)
X(define-key browse-yank-mode-map "i" 'browse-yank-insert)
X(define-key browse-yank-mode-map "h" 'browse-yank-help)
X(define-key browse-yank-mode-map "g" 'browse-yank-to-register)
X(define-key browse-yank-mode-map "e" 'browse-yank-edit)
X
X
X
X(defvar browse-yank-edit-mode-map (copy-keymap text-mode-map)
X "Keymap in use in browse-yank-edit-mode.")
X(define-key browse-yank-edit-mode-map "\C-c\C-c" 'browse-yank-cease-edit)
X(define-key browse-yank-edit-mode-map "\C-c\C-]" 'browse-yank-abort-edit)
X
X
X
X;; define a mode that is only used when executing a browse-yank
X(defun browse-yank-mode ()
X "Major mode for browsing, editing, and inserting elements of the
Xkill-ring. This is a browse-yank specific facility, and should be
Xonly used by the function browse-yank (see browse-yank). Commands
Xare:
X\\{browse-yank-mode-map}"
X
X (kill-all-local-variables)
X (make-local-variable 'mode-line-process)
X (make-local-variable 'minor-mode-alist)
X (mapcar '(lambda (minmode)
X (set (car minmode) nil))
X minor-mode-alist)
X (use-local-map browse-yank-mode-map)
X (setq mode-name "Browse Yank")
X (setq mode-line-process (concat ": "
X browse-yank-cur-txt
X "/"
X browse-yank-max-txt))
X (setq buffer-read-only t)
X (setq major-mode 'browse-yank-mode)
X (goto-char (point-min))
X (run-hooks 'browse-yank-hook))
X
X;; browse-yank ... The command that this whole thing is about
X(defun browse-yank (arg)
X "An interactive kill-ring browsing, editing, and yanking utility.
X
XSee function browse-yank-mode for more details.
X
XAuthor's gripe:
X
X When evaluated, the window split is messy, and I don't like the
Xlossage in the window configuration during the actual browse-yank.
XI'm not sure who's to blame for the appearance. Pop-to-buffer?
XSplit-window? Myself? I cant not have a window 'pop' to the top
X(or bottom) of the screen and not mess up the order of the buffers.
XIf you dont like it, please re-write it, and if you dont want to
Xdo that .... see figure 1."
X
X (interactive "P")
X (if (= 0
X (length kill-ring))
X (progn
X (ding)
X (message browse-yank-barf-message))
X (progn
X (setq browse-yank-orig-window-config (current-window-configuration))
X (pop-to-buffer (get-buffer-create browse-yank-buffer))
X (browse-yank-mode)
X (enlarge-window (- browse-yank-height (window-height)))
X (setq browse-yank-cur 0)
X (browse-yank-make-txt)
X (browse-yank-display 0))))
X
X(defun browse-yank-abort ()
X "Abort a browse-yank."
X (interactive)
X (ding)
X (browse-yank-quit))
X
X(defun browse-yank-quit ()
X "Quit gracefully from a browse-yank"
X (interactive)
X (set-window-configuration browse-yank-orig-window-config)
X (kill-buffer browse-yank-buffer)
X (if browse-yank-inserted-p
X (pop-to-buffer browse-yank-inserted-p)))
X
X(defun browse-yank-insert ()
X "`Yank' the contents of the browse-yank-buffer (an element of the
Xkill-ring) at the point's last location outside of the buffer,
Xcompleting the browse-yank."
X (interactive)
X (save-window-excursion
X (delete-window)
X (setq browse-yank-inserted-p (buffer-name))
X (insert-buffer browse-yank-buffer))
X (browse-yank-quit))
X
X(defun browse-yank-display (browse-yank-yank-to-display)
X "Display the kill-ring ELEMENT in the browse-yank buffer, updating
Xthe mode-line."
X (setq buffer-read-only nil)
X (erase-buffer)
X (goto-char (point-min))
X (insert (nth browse-yank-yank-to-display
X kill-ring))
X (goto-char (point-min))
X (setq mode-line-process (concat ": "
X browse-yank-cur-txt
X "/"
X browse-yank-max-txt))
X (setq buffer-read-only t))
X
X(defun browse-yank-make-txt ()
X "Update the textual versions of the counters used by browse-yank
X (see browse-yank-cur and browse-yank-max)."
X (setq browse-yank-cur-txt (int-to-string (1+ browse-yank-cur)))
X (setq browse-yank-max (1- (length kill-ring)))
X (setq browse-yank-max-txt (int-to-string (1+ browse-yank-max))))
X
X(defun browse-yank-goto-first ()
X "Goto first element of kill-ring in browse-yank-mode."
X (interactive)
X (browse-yank-goto-yank 1))
X
X(defun browse-yank-goto-last ()
X "Goto last element of kill-ring in browse-yank-mode."
X (interactive)
X (browse-yank-goto-yank (length kill-ring)))
X
X(defun browse-yank-locate-regexp (string)
X "Display all elements of kill-ring that contain REGEXP, in
Xbrowse-yank-mode."
X (interactive (list
X (read-from-minibuffer
X (concat "Regexp to locate ["
X search-last-regexp
X "]: "))))
X (if (zerop (length string))
X (setq string search-last-regexp)
X (setq search-last-regexp string))
X (if (zerop (length string))
X (error "Cant search for NULL string")
X (let ((wherebe (mapcar '(lambda (el)
X (if (string-match string el)
X t))
X kill-ring))
X (loc ""))
X (for i 0 (length wherebe)
X (if (car (nthcdr i wherebe))
X (setq loc (concat loc
X (prin1-to-string (1+ i))
X ","))))
X (if (zerop (length loc))
X (progn (ding)
X (message "String not found in any yanks."))
X (setq loc (substring loc
X 0
X (1- (length loc))))
X (message (concat "Found in yanks: "
X loc
X "."))))))
X
X
X(defun browse-yank-search-backward (string)
X "Search backward in kill ring for REGEXP, in browse-yank-mode."
X (interactive (list (read-from-minibuffer
X (concat "Search backwards for regexp ["
X search-last-regexp
X "]: "))))
X (cond ((zerop (length string))
X (setq string search-last-regexp)
X (setq search-last-regexp string))
X ((zerop (length string))
X (nil))
X (t
X (let ((loc (1+ (regexp-search-list string
X (nthcdr (- (length kill-ring)
X browse-yank-cur)
X (reverse kill-ring))))))
X (if (<= loc browse-yank-cur)
X (progn
X (browse-yank-next-yank loc)
X (goto-char (1+ (string-match string
X (buffer-substring (point-min)
X (point-max))))))
X (error "Search failed: \"%s\"" string))))))
X
X
X(defun browse-yank-search-forward (string)
X "Search forward for a occurance of REGEXP in kill-ring, for
Xbrowse-yank."
X (interactive (list (read-from-minibuffer
X (concat "Search forward for regexp ["
X search-last-regexp
X "]: "))))
X (if (zerop (length string))
X (setq string search-last-regexp)
X (setq search-last-regexp string))
X (if (zerop (length string))
X (nil)
X (let ((loc (regexp-search-list string
X kill-ring
X (1+ browse-yank-cur))))
X (if (= loc (length kill-ring))
X (error "Search failed: \"%s\"" string)
X (browse-yank-goto-yank (1+ loc)))
X (goto-char (1+ (string-match string
X (buffer-substring (point-min)
X (point-max))))))))
X
X(defun browse-yank-goto-yank (arg)
X "Display the supplied kill-ring position in the browse-yank-buffer."
X (interactive "nGoto yank: ")
X (cond ((< arg 1)
X (error "Argument must be positive."))
X ((> arg (length kill-ring))
X (error "Argument exceeds the length of kill-ring."))
X (t
X (setq browse-yank-cur (1- arg))
X (browse-yank-make-txt)
X (browse-yank-display browse-yank-cur))))
X
X(defun browse-yank-next-yank (arg)
X "Goto the next element of the kill-ring in browse-yank buffer."
X (interactive "p")
X (let ((temp-pos (- browse-yank-cur arg)))
X (cond ((< temp-pos 0)
X (error "No following item in kill-ring."))
X ((> temp-pos (- (length kill-ring) 1))
X (error "No preceding item in kill-ring."))
X (t
X (setq browse-yank-cur (- browse-yank-cur arg))
X (browse-yank-make-txt)
X (browse-yank-display browse-yank-cur)))))
X
X(defun browse-yank-previous-yank (arg)
X "Goto the previous element of the kill-ring in browse-yank buffer."
X (interactive "p")
X (browse-yank-next-yank (- arg)))
X
X(defun buffer-to-register (char)
X"Set the contents of the current buffer into register CHAR."
X (interactive "cCopy to register: ")
X (set-register char (buffer-substring (point-min) (point-defun))))
X(fset 'browse-yank-to-register
X (symbol-function 'buffer-to-register))
X
X(defun browse-yank-help ()
X "Spit out a simple help message for browse-yank-mode."
X (interactive)
X (message "(e)dit (i)nsert (j)ump (l)ocate (n)ext (p)revious (q)uit (?)describe-mode"))
X
X(defun browse-yank-yanks-saved (string)
X "Set kill-ring-max to a user defined value and make sure that
Xdisplayed information is valid and sane."
X (interactive (list (read-from-minibuffer
X (concat "Number of elements in kill-ring ["
X kill-ring-max
X "]: "))))
X (if (not (zerop (length string)))
X (let ((size (string-to-int string)))
X (if (or (not (numberp size))
X (<= size 0))
X (error "Please give a positive number."))
X (setq kill-ring-max size)
X (if (> (length kill-ring) kill-ring-max)
X (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
X (setq kill-ring-yank-pointer kill-ring)
X (if (< size (1+ browse-yank-max))
X (progn
X (setq browse-yank-max size)
X (if (< size (1+ browse-yank-cur))
X (progn
X (setq browse-yank-cur browse-yank-max)
X (browse-yank-goto-yank browse-yank-cur))
X (browse-yank-goto-yank (1+ browse-yank-cur))))))))
X
X(defun browse-yank-edit-mode ()
X "Major mode for editing the contents of a Yank Buffer
XThe editing commands are the same as in Text mode, together with two commands
Xto return to regular Browse Yank Mode:
X\\{browse-yank-edit-mode-map}?
X
XThis mode runs the contents of browse-yank-edit-mode-hook if it exists."
X (use-local-map browse-yank-edit-mode-map)
X (setq major-mode 'browse-yank-edit-mode)
X (setq mode-name "Browse Yank Edit")
X (run-hooks 'browse-yank-edit-mode-hook))
X
X(defun browse-yank-edit ()
X "Edit the browse-yank buffer; switch to browse-yank-edit-mode."
X (interactive)
X (browse-yank-edit-mode)
X (setq buffer-read-only nil)
X (set-buffer-modified-p (buffer-modified-p))
X (setq mode-line-process (concat "ing: "
X browse-yank-cur-txt))
X (message "Editing: Type C-c C-c to return to Browse Yank, C-c C-] to abort."))
X
X(defun browse-yank-cease-edit ()
X "Finish editing message; switch back to Browse Yank proper."
X (interactive)
X (rplaca (nthcdr browse-yank-cur kill-ring)
X (buffer-substring (point-min)
X (point-max)))
X (setq buffer-read-only t)
X (browse-yank-mode)
X (browse-yank-display browse-yank-cur))
X
X(defun browse-yank-abort-edit ()
X "Abort edit of browse-yank buffer; restore original contents."
X (interactive)
X (setq buffer-read-only t)
X (browse-yank-mode)
X (browse-yank-display browse-yank-cur))
X
X(defun regexp-search-list (re l &optional start)
X "Return position of first occurence of REGEXP in LIST starting
Xat position START (optional)."
X (if (null start)
X (setq start 0))
X (+ start
X (- (length (nthcdr start l))
X (length (memq t (mapcar '(lambda (el)
X (if (string-match re
X el)
X t))
X (nthcdr start l)))))))
X
X
X
X; /Bob...
X;--
X;{...}!rutgers!mende mende@aramis.rutgers.edu mende@zodiac.bitnet
X;
X;STEVEN SPEILBERG has a hangnail on his left foot, I am so envious!
X
SHAR_EOF
chmod 0644 browse-yank.el || echo "restore of browse-yank.el fails"
set `wc -c browse-yank.el`;Sum=$1
if test "$Sum" != "15043"
then echo original size 15043, current size $Sum;fi
fi
exit 0
Technical Details
Message-ID:
<NK.92Feb20210502@fubuki.ics.osaka-u.ac.jp>Path:
arc1-ca.pugleaf.net!sparky!uunet!think.com!mips!panasonic.com!chorus.mei!icspub!fubuki!nkReferences:
<NK.92Feb11234420@fubuki.ics.osaka-u.ac.jp>Show Full Headers
Complete Article Headers
X-Google-Language: Japanese,JIS X-Google-Thread: ff358,f81c01cb8bd2b987 X-Google-Attributes: gidff358,public X-Google-ArrivalTime: 1992-02-20 04:26:24 PST Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!mips!panasonic.com!chorus.mei!icspub!fubuki!nk From: nk@ics.osaka-u.ac.jp (Noriya KOBAYASHI) Newsgroups: fj.editor.emacs Subject: browse-yank.el (Re: How to utilize Emacs well sans effort. #2) Message-ID: <NK.92Feb20210502@fubuki.ics.osaka-u.ac.jp> Date: 20 Feb 92 12:05:02 GMT References: <NK.92Feb11234420@fubuki.ics.osaka-u.ac.jp> Sender: news@icspub.ics.osaka-u.ac.jp Distribution: fj Organization: Dept. of Information & Computer Sciences, Osaka Univ., JAPAN Lines: 468 In-reply-to: nk@ics.osaka-u.ac.jp's message of 11 Feb 92 14:44:20 GMT