Article View: gnu.emacs.bug
Article #812insert-buffer interactive default
From: Richard Mlynarik
Date: Fri, 02 Oct 1992 21:12
Date: Fri, 02 Oct 1992 21:12
133 lines
6346 bytes
6346 bytes
In article <1992Oct2.133603.28087@linus.mitre.org> djb@bambam.ai.mit.EDU (David J. Braunegg) writes:
>>In the definition of insert-buffer in simple.el, I suggest replacing
>> (interactive "*bInsert buffer: ")
>>with
>> (interactive "*BInsert buffer: ")
>
>The interactive "B" code will allow you to specify a nonexistent buffer,
>which you don't want for insert-buffer. You'll at least have to change the
>code for insert-buffer to check whether get-buffer returns a buffer or nil,
>so it can print an error if the user specifies a nonexistent buffer.
OK, this would be a reasonable change and also keep the changes
minimal.
Or, insert-buffer could be re-written in C instead of elisp. Then the
default could be the previous buffer and nonexistent buffers could be
handled correctly. The C programming for this is a little beyond me,
though.
It is always infinitely easier to accomplish any task in Lisp than in C.
This holds in all problem domains, not just Emacs.
(BTW I've recently rewritten the Emacs command-loop and all the
minibuffer code in Lisp. It is a many times easier to understand and change.)
Rather than redefining insert-buffer, I just patch its
interactive-argument-reading code. This way I'm sure not to alter the
base behaviour of the function if it should change from release to
release.
Put this in your init file. It has been in mine for years.
(or (fboundp 'original-insert-buffer)
(fset 'original-insert-buffer (symbol-function 'insert-buffer)))
(defun insert-buffer (buffer)
"Insert after point the contents of BUFFER.
Puts mark after the inserted text.
BUFFER may be a buffer or a buffer name."
;; >> Fix cretinous default of inserting current buffer into itself
(interactive
(list
(progn (barf-if-buffer-read-only)
(read-buffer "Insert buffer: " (other-buffer) t))))
(original-insert-buffer buffer))
I have a whole slew of other patches to correct broken default Emacs
behaviours.
Perhaps I should post my emacs-init.el to gnu.emacs.sources as an
example of a Cultural Treasure?
;; like in $el/files.el, expect that I won't create a new
;; buffer unless a prefix arg is given
(or (fboundp 'original-switch-to-buffer)
(fset 'original-switch-to-buffer (symbol-function 'switch-to-buffer)))
(defun switch-to-buffer (buffer &optional norecord)
"Select buffer BUFFER in the current window.
BUFFER may be a buffer or a buffer name.
Optional second arg NORECORD non-nil means
do not put this buffer at the front of the list of recently selected ones.
WARNING: This is NOT the way to work on another buffer temporarily
within a Lisp program! Use `set-buffer' instead. That avoids messing with
the window-buffer correspondances."
(interactive
(list (read-buffer "Switch to buffer: "
(other-buffer (current-buffer))
(null current-prefix-arg))))
(original-switch-to-buffer buffer norecord))
(defun switch-to-buffer-other-window (buffer)
"Select buffer BUFFER in another window."
(interactive
(list (read-buffer "Switch to buffer in other window: "
(other-buffer (current-buffer))
(null current-prefix-arg))))
(let ((pop-up-windows t))
(pop-to-buffer buffer t)))
;; Lucid Emacs 19/Emacs 18
(if (not (fboundp 'next-line-internal)) (fset 'next-line-internal 'line-move))
;; same as in $el/simple.el except that c-N at end of buffer doesn't
;; create any new lines. That has always seemed a misfeature to me...
(defun next-line (arg)
">>If on the last line of the buffer, just moves to the end of the buffer."
(interactive "p")
(if (= arg 1)
(let ((opoint (point)))
(forward-line 1)
(if (or (= opoint (point))
(not (eq (preceding-char) ?\n)))
(progn (goto-char (point-max))
(signal 'end-of-buffer ()))
(goto-char opoint)
(next-line-internal arg)))
(next-line-internal arg))
nil)
;; Bloody brain-dead unix doesn't have undelete
(or (fboundp 'original-delete-file)
(fset 'original-delete-file (symbol-function 'delete-file)))
(defun delete-file (filename &optional confirm)
"Delete specified file. One argument, a file name string.\n\
If file has multiple names, it continues to exist with the other names.
>> If called interactively, user is asked for confirmation before file is deleted
>> in order to attempt to compensate for the subfunctional unix filesystem."
(interactive
(list (read-file-name (format "Delete file (default %s): "
(cond ((not (stringp buffer-file-name))
"")
((string= default-directory
(file-name-directory
buffer-file-name))
(file-name-nondirectory
buffer-file-name))
(t
buffer-file-name)))
nil nil 'confirm)
t))
(setq filename (expand-file-name filename))
(if (and confirm
(file-exists-p filename)
;; Don't ask if we're going to blow out anyway.
(not (file-directory-p filename)))
(if (not (y-or-n-p (format "PERMANENTLY delete %s? "
(prin1-to-string filename))))
(error "%s not deleted." filename)
(progn
(original-delete-file filename)
(message "%s deleted" (prin1-to-string filename))))
(original-delete-file filename)))
Technical Details
Message-ID:
<MLY.92Oct2211230@atalanta.parc.xerox.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!lcs.mit.edu!MlyShow Full Headers
Complete Article Headers
Newsgroups: gnu.emacs.bug Path: arc1-ca.pugleaf.net!sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!lcs.mit.edu!Mly From: Mly@lcs.mit.edu (Richard Mlynarik) Subject: insert-buffer interactive default Message-ID: <MLY.92Oct2211230@atalanta.parc.xerox.com> Sender: gnulists@ai.mit.edu Reply-To: Mly@lcs.mit.edu Organization: Xerox PARC, Palo Alto, CA Distribution: gnu Date: Fri, 2 Oct 1992 21:12:30 GMT Approved: bug-gnu-emacs@prep.ai.mit.edu Lines: 134