[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Storing of a buffer line number to a file
From: |
Jason Earl |
Subject: |
Re: Storing of a buffer line number to a file |
Date: |
Mon, 24 Mar 2003 19:34:22 -0700 |
User-agent: |
Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.2 (gnu/linux) |
Bastien Guerry <bastien1@free.fr> writes:
> Alexandre S Iline <shurymury@yandex.ru> :
>
>> Thank you very much - it helps a lot.
>
>> But, I'm still wondering: is there any simplier way to
>> write something to file?
>
> ,----[ with-temp-file ]
> | - Macro: with-temp-file file body...
> | The `with-temp-file' macro evaluates the BODY forms with a
> | temporary buffer as the current buffer; then, at the end, it
> | writes the buffer contents into file FILE. It kills the temporary
> | buffer when finished, restoring the buffer that was current before
> | the `with-temp-file' form. Then it returns the value of the last
> | form in BODY.
> |
> | The current buffer is restored even in case of an abnormal exit via
> | `throw' or error (*note Nonlocal Exits::).
> |
> | See also `with-temp-buffer' in *Note Current Buffer::.
> `----
>
> This should do the work:
>
> (defun my-what-line ()
> "Insert the line number into a temporary file."
> (interactive)
> (let ((num (count-lines 1 (point))))
> (with-temp-file "~/linenum.txt"
> (insert (int-to-string num)))))
>
> Try also to evaluate:
>
> (info "(elisp)Writing to files")
>
>
> \bye
>
> --
> Bastien
Holy Mackerel. That (info "(elisp)Writing to files") trick is a very
cool. A simple C-x C-e and I jumped to the info node.
Thanks!