[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: |
Merciadri Luca |
Subject: |
Re: Adding `#' at each new line with text until the end of the file |
Date: |
Wed, 08 Dec 2010 15:08:47 -0000 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
pjb@informatimago.com (Pascal J. Bourguignon) writes:
>> Sure, but, as I explained in my previous message, it does not even
>> modify the Sayings file. Why?
>
> Because you didn't instruct the program to modify the file.
> Read the documentation of insert, for example. Does it mention files?
> What does insert modify?
Insert modifies the current buffer, according to the manual. Or
find-file loads its arg into a buffer. So, if find-file loads its arg
into the *current* buffer, insert should modify the current buffer,
that is, `Sayings'.
> Here is a macro that could be useful:
>
> (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
> (,(if literal 'find-file-literally 'find-file) ,path)
> (prog1 (save-excursion ,@body)
> ,(when save `(save-buffer 1))))
> ,(when kill
> `(kill-buffer (current-buffer)))))))
Thanks. I'll keep it.
- --
Merciadri Luca
See http://www.student.montefiore.ulg.ac.be/~merciadri/
- --
The whole dignity of man lies in the power of thought.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
iEYEARECAAYFAkvyxLcACgkQM0LLzLt8MhyKawCfXMN2zho0p+/bBEc1gQAG3YmD
MO4AoK6a8STV9snV2hmw0the3TF9GnIy
=CMWS
-----END PGP SIGNATURE-----
- 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 <=
- 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, 2010/12/08