Article View: gnu.emacs.help
Article #189614Re: GNU Emacs Frequently Asked Questions with Answers (part 2 of 2)
From: tucker
Date: Fri, 14 Dec 1990 17:21
Date: Fri, 14 Dec 1990 17:21
148 lines
5206 bytes
5206 bytes
I use this little package to switch between buffers very quickly.
It is also useful to define routines in your init that will give
nicknames to several related files. For example, when I work on g++, I
execute the following setup command.
(defunx gnu-setup () (interactive)
(basic-setup)
(pop-to-buffer "*shell*")
(end-of-buffer)
(execute-kbd-macro "cd /home/users1/tucker/g/g++\r")
(find-file-other-window "tour.t") (name-friend ?\^t)
(progn (find-file-other-window "cplus-parse.y") (name-friend ?\^y))
(progn (find-file-other-window "cplus-lex.c") (name-friend ?\^l))
(progn (find-file-other-window "cplus-decl.c") (name-friend ?\^d))
(progn (find-file-other-window "cplus-tree.c") (name-friend ?\^e))
(progn (find-file-other-window "tree.def") (name-friend ?E))
(progn (find-file-other-window "tree.h") (name-friend ?e))
(progn (find-file-other-window "vz.i") (name-friend ?\^i))
(progn (find-file-other-window "print-tree.c") (name-friend ?p))
)
-- Enjoy.
Mark Tucker
;;
;;Author: Mark Tucker
;; Philips Research
;; tucker@prle.prl.philips.nl
;; 14 Dec 90
;
;OVERVIEW:
;
;The friends package is designed to help you switch between buffers when
;you're dealing with many buffers at a time. You give buffers one
;character nicknames, and switch to them with a 3 keystroke command.
;
;Suppose you give the current C file the nickname "^C".
;Then holding control down and hitting X COMMA C (ie, ^X,^C)
;(Notice: control-comma is the same as comma) puts the current C
;file into the current window.
;
;DETAILS:
;
;The function pop-to-friend is bound to 'control-x commma'. If
;you give it a prefix argument by giving ^U, then pop-to-friend
;asks you to name the current buffer.
;
;USAGE:
;By convention, I name C files by lower case letters (ie, chars.c
;would be friend 'c') and header files by capital letters (chars.h
;would be friend 'C'). And use very easy patterns (where the
;friend is named with a control character) for especially commonly
;accessed files.
;
;
;SUMMARY: (via example)
;^X^,^C : pops to friend named ^C
;^U^X^,^C: Name the current buffer ^C.
;^U^U^x^C : Name the current window configuration ^C.
;
;
;
;
; Now lets you remember window configurations.
;
; ^x,C -- pop to friend named C
; ^ux,C -- give a buffer a name
; ^u^ux,C -- name a window configuration friend.
;
(defmacro was-arg-given () '(not (= arg 1)))
(defmacro U-given () '(= arg 4))
(defmacro UU-given () '(= arg 16))
(defun name-friend (char)
(setq s (concat "*friend" (char-to-string char) "*"))
(setq sy (intern s)) (set sy (current-buffer))
)
; (name-friend ?)
(defun friends-entrypoint (arg) (interactive "p")
(cond
((UU-given)(make-window-friend))
((U-given)(make-buffer-friend))
(t (visit-friend))))
(defun i-get-friend-sym (pmt)
(let ( (c (progn (message pmt) (read-char))))
(intern (concat "*friend" (char-to-string c) "*"))))
(defun make-buffer-friend ()
(let ( (sy (i-get-friend-sym "Char to name this buffer?: " )))
(message "Set symbol %s to %s" (symbol-name sy)
(prin1-to-string (current-buffer)))
(set sy (current-buffer))
(sit-for 3)))
(defun make-window-friend()
(let ( (sy (i-get-friend-sym "Char to name this WINDOW CONFIGURATION?: " )))
(message "Set symbol %s to %s" (symbol-name sy)
(prin1-to-string (current-window-configuration)))
(set sy (current-window-configuration))
(sit-for 3)))
(defun visit-friend ()
(let ( (sy (i-get-friend-sym "Friend to visit?: "))
sydef)
(if (not (boundp sy))
(error "No friend named:%s " (name-of-friend sy)))
(setq sydef (symbol-value sy))
(cond
((bufferp sydef) (switch-to-buffer sydef))
(t (set-window-configuration sydef)))))
(global-set-key "\^x," 'friends-entrypoint)
(defun name-of-friend (sy)
(let ( (sn (symbol-name sy)))
(if (string-match "^.friend..$" sn)
(substring sn -2 -1)
(error "{%s} is not friendly !" sn))
))
(defun describe-friends ()(interactive)
(pop-to-buffer "*Friends*")
(erase-buffer)
(insert "\nFriends:\n\n")
(mapatoms '(lambda (sy)
(let ( (sn (symbol-name sy)))
(if (string-match "^.friend..$" sn); "^\\*friend\\(.\\)$"
(insert
"\t"
(substring sn -2 -1)
" : "
; sn " : "
(prin1-to-string (if (boundp sy)
(symbol-value sy)"?UNBOUND?")
)
"\n")))))
)
Technical Details
Message-ID:
<2414@prles2.prl.philips.nl>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!hp4nl!phigate!prle!prles2!prles9k!tuckerReferences:
<JBW.90Dec8014613@bucsf.bu.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103b8b,1744ac1b923f97ed X-Google-Attributes: gid103b8b,public X-Google-ArrivalTime: 1990-12-14 09:21:32 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!hp4nl!phigate!prle!prles2!prles9k!tucker From: tucker@prles9k.prl.philips.nl (tucker) Newsgroups: gnu.emacs.help Subject: Re: GNU Emacs Frequently Asked Questions with Answers (part 2 of 2) Message-ID: <2414@prles2.prl.philips.nl> Date: 14 Dec 90 17:21:32 GMT References: <JBW.90Dec8014613@bucsf.bu.edu> Sender: news@prles2.prl.philips.nl Reply-To: tucker@prles9k.UUCP (tucker) Organization: Philips Research Laboratories, Eindhoven the Netherlands Lines: 148