all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Storing of a buffer line number to a file
@ 2003-03-24 19:49 Alexandre S Iline
  2003-03-24 19:56 ` Bastien Guerry
  0 siblings, 1 reply; 6+ messages in thread
From: Alexandre S Iline @ 2003-03-24 19:49 UTC (permalink / raw)


It's rather a list question, probably, bu anyway ...

I got stuck - do not know how to do it.

I'm trying to create a list function which would simply
output a number of a currently selected line in the selected buffer.

I have no problem in line number recieving:
(count-lines 1 (point)), but then, what should I do with the value?

I guess, it's pretty simple, but nothing from documentation I have,
helps me to find the answer.

Thanks in advance.

Shura.

PS: I'm very new in that, so, don't beat me, please, if the question is 
too stupid. :)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Storing of a buffer line number to a file
  2003-03-24 19:49 Storing of a buffer line number to a file Alexandre S Iline
@ 2003-03-24 19:56 ` Bastien Guerry
  2003-03-24 20:51   ` Alexandre S Iline
  0 siblings, 1 reply; 6+ messages in thread
From: Bastien Guerry @ 2003-03-24 19:56 UTC (permalink / raw)


Alexandre S Iline <shurymury@yandex.ru> hat geschrieben:

> I'm trying to create a list function which would simply
> output a number of a currently selected line in the selected buffer.

(insert (int-to-string (count-lines (point-min) (point))))

... will insert the current line number in your buffer just after the
point location.  Maybe you will be also interested by the `what-line'
command.

-- 
Bastien

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Storing of a buffer line number to a file
  2003-03-24 19:56 ` Bastien Guerry
@ 2003-03-24 20:51   ` Alexandre S Iline
  2003-03-24 21:24     ` Bastien Guerry
  0 siblings, 1 reply; 6+ messages in thread
From: Alexandre S Iline @ 2003-03-24 20:51 UTC (permalink / raw)


Thank you very much - it helps a lot.

Now I'm able to create the function I need:
(defun my-what-line ()
   (interactive)
   (let (buff line)
     (setq line (int-to-string (count-lines (point-min) (point))))
     (kill-buffer (get-buffer-create "linenum"))
     (find-file "/tmp/linenum");
     (delete-region (point-min) (point-max))
     (insert line)
     (insert "\n")
     (save-buffer)
     (kill-buffer (get-buffer-create "linenum"))))

It does exactly what I need.

But, I'm still wondering: is there any simplier way to
write something to file?

Thanks.

Shura.

Bastien Guerry wrote:
> Alexandre S Iline <shurymury@yandex.ru> hat geschrieben:
> 
> 
>>I'm trying to create a list function which would simply
>>output a number of a currently selected line in the selected buffer.
> 
> 
> (insert (int-to-string (count-lines (point-min) (point))))
> 
> ... will insert the current line number in your buffer just after the
> point location.  Maybe you will be also interested by the `what-line'
> command.
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Storing of a buffer line number to a file
  2003-03-24 20:51   ` Alexandre S Iline
@ 2003-03-24 21:24     ` Bastien Guerry
  2003-03-25  2:34       ` Jason Earl
  0 siblings, 1 reply; 6+ messages in thread
From: Bastien Guerry @ 2003-03-24 21:24 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Storing of a buffer line number to a file
  2003-03-24 21:24     ` Bastien Guerry
@ 2003-03-25  2:34       ` Jason Earl
  2003-03-25  3:44         ` Unknown
  0 siblings, 1 reply; 6+ messages in thread
From: Jason Earl @ 2003-03-25  2:34 UTC (permalink / raw)


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!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Storing of a buffer line number to a file
  2003-03-25  2:34       ` Jason Earl
@ 2003-03-25  3:44         ` Unknown
  0 siblings, 0 replies; 6+ messages in thread
From: Unknown @ 2003-03-25  3:44 UTC (permalink / raw)


Jason Earl wrote:

> 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.

yep.  But it'd be even better if you could find such information in the future 
for yourself.  Try pressing "i" while browsing the emacs-lisp info files, I 
can see a whole bunch of index entries relating to writing to files.  Also, 
you can perform regular expression searching across nodes with with "s".

--
Le

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-03-25  3:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-24 19:49 Storing of a buffer line number to a file Alexandre S Iline
2003-03-24 19:56 ` Bastien Guerry
2003-03-24 20:51   ` Alexandre S Iline
2003-03-24 21:24     ` Bastien Guerry
2003-03-25  2:34       ` Jason Earl
2003-03-25  3:44         ` Unknown

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.