From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: How to modify 'write-file' Date: Wed, 14 Apr 2010 02:37:37 +0200 Organization: Informatimago Message-ID: <87mxx698dq.fsf@galatea.lan.informatimago.com> References: <87ochrgpbd.fsf@galatea.lan.informatimago.com> <9f65fba7-3fba-40b6-ad86-75aa4f336b91@g11g2000yqe.googlegroups.com> <87bpdpftpa.fsf@galatea.lan.informatimago.com> <9345ad4d-220c-4319-9e2f-d5acfa340d27@35g2000yqm.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1273006284 8220 80.91.229.12 (4 May 2010 20:51:24 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 4 May 2010 20:51:24 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 04 22:51:22 2010 connect(): No such file or directory Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1O9P5N-0004cV-5Y for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 22:51:21 +0200 Original-Received: from localhost ([127.0.0.1]:52530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9P5M-0002XH-Ko for geh-help-gnu-emacs@m.gmane.org; Tue, 04 May 2010 16:51:20 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 164 Original-X-Trace: individual.net ftnf90y1esBeUKAykB2/OQj79Jksbhlrp/g9YOOKhtLKYIxMGt Cancel-Lock: sha1:MGUyOWM5OWFiY2M3ZjYzMTBlYTk2MmNiYjc3NmJkOGJmNWE3NTBlNw== sha1:9sPHBw611oJm//xHCnBSNCELBr4= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (darwin) Original-Xref: usenet.stanford.edu gnu.emacs.help:177694 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:73155 Archived-At: "richard.christensen" writes: > Hi Pascal, > > I am sorry for being thick. I have tried several things and have > tried to do some > reading about how to implement this code. I can't get anything to > work. I can > see what appears to be the correct words on the minibuffer, but upon > hitting enter, > either nothing happens or I get an error about wrong number of > arguments. > > Should I be doing this (defun write-file (arg) or should I be creating > a new function? > I see that a list is created but I am sure the write-file does not > want the "Write file:" text > to be part of the operation. So, some how I need to re-direct the > path and file name from the list > back to the write-function. Am I missing anything else? Sorry, I assumed you were already a seasoned emacs lisp programmer. Here are detailed instructions: 1- Find the sources of write-file, type: C-h f write-file RET C-x o TAB RET 2- Copy and paste the defun write-file form to the *scratch* buffer: C-SPC C-M-f M-w C-x b *scratch* RET RET C-y C-M-b You get this in the *scratch* buffer: (defun write-file (filename &optional confirm) "Write current buffer into file FILENAME. This makes the buffer visit that file, and marks it as not modified. If you specify just a directory name as FILENAME, that means to use the default file name but in that directory. You can also yank the default file name into the minibuffer to edit it, using \\\\[next-history-element]. If the buffer is not already visiting a file, the default file name for the output file is the buffer name. If optional second arg CONFIRM is non-nil, this function asks for confirmation before overwriting an existing file. Interactively, confirmation is required unless you supply a prefix argument." ;; (interactive "FWrite file: ") (interactive (list (if buffer-file-name (read-file-name "Write file: " nil nil nil nil) (read-file-name "Write file: " default-directory (expand-file-name (file-name-nondirectory (buffer-name)) default-directory) nil nil)) (not current-prefix-arg))) (or (null filename) (string-equal filename "") (progn ;; If arg is just a directory, ;; use the default file name, but in that directory. (if (file-directory-p filename) (setq filename (concat (file-name-as-directory filename) (file-name-nondirectory (or buffer-file-name (buffer-name)))))) (and confirm (file-exists-p filename) (or (y-or-n-p (format "File `%s' exists; overwrite? " filename)) (error "Canceled"))) (set-visited-file-name filename (not confirm)))) (set-buffer-modified-p t) ;; Make buffer writable if file is writable. (and buffer-file-name (file-writable-p buffer-file-name) (setq buffer-read-only nil)) (save-buffer) ;; It's likely that the VC status at the new location is different from ;; the one at the old location. (vc-find-file-hook)) 3- Replace the interactive form in this defun by the one I provided: (interactive (list (if buffer-file-name (read-file-name "Write file: " default-directory (expand-file-name (file-name-nondirectory (buffer-name)) default-directory) nil (buffer-name)) (read-file-name "Write file: " default-directory (expand-file-name (file-name-nondirectory (buffer-name)) default-directory) nil nil)) (not current-prefix-arg))) so that you get: (defun write-file (filename &optional confirm) "Write current buffer into file FILENAME. This makes the buffer visit that file, and marks it as not modified. If you specify just a directory name as FILENAME, that means to use the default file name but in that directory. You can also yank the default file name into the minibuffer to edit it, using \\\\[next-history-element]. If the buffer is not already visiting a file, the default file name for the output file is the buffer name. If optional second arg CONFIRM is non-nil, this function asks for confirmation before overwriting an existing file. Interactively, confirmation is required unless you supply a prefix argument." (interactive (list (if buffer-file-name (read-file-name "Write file: " default-directory (expand-file-name (file-name-nondirectory (buffer-name)) default-directory) nil (buffer-name)) (read-file-name "Write file: " default-directory (expand-file-name (file-name-nondirectory (buffer-name)) default-directory) nil nil)) (not current-prefix-arg))) (or (null filename) (string-equal filename "") (progn ;; If arg is just a directory, ;; use the default file name, but in that directory. (if (file-directory-p filename) (setq filename (concat (file-name-as-directory filename) (file-name-nondirectory (or buffer-file-name (buffer-name)))))) (and confirm (file-exists-p filename) (or (y-or-n-p (format "File `%s' exists; overwrite? " filename)) (error "Canceled"))) (set-visited-file-name filename (not confirm)))) (set-buffer-modified-p t) ;; Make buffer writable if file is writable. (and buffer-file-name (file-writable-p buffer-file-name) (setq buffer-read-only nil)) (save-buffer) ;; It's likely that the VC status at the new location is different from ;; the one at the old location. (vc-find-file-hook)) 4- Evaluate this defun, for example positionning the cursor after it, and typing C-x C-e. 5- Use the new write-file. If you want to keep this version of write-file, you can copy-and-paste it into your ~/.emacs file. -- __Pascal Bourguignon__