[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Adding `#' at each new line with text until the end of the file
From: |
Andreas Politz |
Subject: |
Re: Adding `#' at each new line with text until the end of the file |
Date: |
Wed, 08 Dec 2010 15:09:16 -0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> writes:
>> Here with find-file-noselect as it has been advised (not tested):
>>
>> (require 'cl)
>> (defmacro* with-file (file-and-options &body body)
>> "Processes BODY with a buffer on the given file.
>> DO: find-file or find-file-literally, process body, and
>> optionally save the buffer and kill it.
>> save is not done if body exits exceptionnaly.
>> kill is always done as specified.
>> FILE-AND-OPTION: either an atom evaluated to a path,
>> or (path &key (save t) (kill t) (literal nil))
>> "
>> (if (atom file-and-options)
>> `(with-file (,file-and-options) ,@body)
>> ;; destructuring-bind is broken, we cannot give anything else than nil
>> ;; as default values:
>> (destructuring-bind (path &key (save nil savep) (kill nil killp)
>> (literal nil literalp))
>> file-and-options
>> (unless savep (setf save t))
>> (unless killp (setf kill t))
>> `(unwind-protect
>> (progn
>> (find-file-noselect ,path t ,literal)
>> (prog1 (save-excursion ,@body)
>> ,(when save `(save-buffer 1))))
>> ,(when kill
>> `(kill-buffer (current-buffer)))))))
>>
This macro may kill buffers at random, because `find-file-noselect' does
not make the files buffer current.
But even with `find-file', this may go wrong, in case the function does
not succeed or body changes the current buffer.
-ap
- Adding `#' at each new line with text until the end of the file, Merciadri Luca, 2010/12/08
- Re: Adding `#' at each new line with text until the end of the file, Pascal J. Bourguignon, 2010/12/08
- Re: Adding `#' at each new line with text until the end of the file, Merciadri Luca, 2010/12/08
- Message not available
- Re: Adding `#' at each new line with text until the end of the file, Merciadri Luca, 2010/12/08
- Re: Adding `#' at each new line with text until the end of the file, Pascal J. Bourguignon, 2010/12/08
- Re: Adding `#' at each new line with text until the end of the file, Merciadri Luca, 2010/12/08
- Re: Adding `#' at each new line with text until the end of the file, Pascal J. Bourguignon, 2010/12/08
- Re: Adding `#' at each new line with text until the end of the file, Merciadri Luca, 2010/12/08
- Re: Adding `#' at each new line with text until the end of the file, Pascal J. Bourguignon, 2010/12/08
- Re: Adding `#' at each new line with text until the end of the file, Merciadri Luca, 2010/12/08
- Re: Adding `#' at each new line with text until the end of the file,
Andreas Politz <=