all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Reading from a buffer
@ 2020-07-01 19:12 Greg Hill
  2020-07-01 19:19 ` Eli Zaretskii
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Greg Hill @ 2020-07-01 19:12 UTC (permalink / raw)
  To: help-gnu-emacs

I've pretty well mastered the process of *writing to* a buffer using
*insert* and *format*, but I haven't been able to find any equally easy way
to read that same information back. I've hacked together a workaround using
*copy-to-register*, *get-register* and *read-from-string*, but surely there
must be a more straightforward approach than that. I've searched and
searched through all the documentation and have come up with nothing for
doing a simple formatted read from buffer. Any suggestions?


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

* Re: Reading from a buffer
  2020-07-01 19:12 Reading from a buffer Greg Hill
@ 2020-07-01 19:19 ` Eli Zaretskii
  2020-07-01 19:20 ` Emanuel Berg via Users list for the GNU Emacs text editor
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Eli Zaretskii @ 2020-07-01 19:19 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Greg Hill <gregoryohill@gmail.com>
> Date: Wed, 1 Jul 2020 12:12:06 -0700
> 
> I've pretty well mastered the process of *writing to* a buffer using
> *insert* and *format*, but I haven't been able to find any equally easy way
> to read that same information back. I've hacked together a workaround using
> *copy-to-register*, *get-register* and *read-from-string*, but surely there
> must be a more straightforward approach than that. I've searched and
> searched through all the documentation and have come up with nothing for
> doing a simple formatted read from buffer. Any suggestions?

Formatted read to read what? numbers? like number-at-point?



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

* Re: Reading from a buffer
  2020-07-01 19:12 Reading from a buffer Greg Hill
  2020-07-01 19:19 ` Eli Zaretskii
@ 2020-07-01 19:20 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2020-07-01 19:21 ` Jakub Jankiewicz
  2020-07-01 19:21 ` Jakub Jankiewicz
  3 siblings, 0 replies; 10+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-07-01 19:20 UTC (permalink / raw)
  To: help-gnu-emacs

Greg Hill wrote:

> I've pretty well mastered the process of *writing
> to* a buffer using *insert* and *format*, but
> I haven't been able to find any equally easy way to
> read that same information back. I've hacked
> together a workaround using *copy-to-register*,
> *get-register* and *read-from-string*, but surely
> there must be a more straightforward approach than
> that. I've searched and searched through all the
> documentation and have come up with nothing for
> doing a simple formatted read from buffer.
> Any suggestions?

(buffer-substring ...)

(with-current-buffer ".emacs"
  (buffer-substring-no-properties (point-min) (point-max)) )

(buffer-string)

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: Reading from a buffer
  2020-07-01 19:12 Reading from a buffer Greg Hill
  2020-07-01 19:19 ` Eli Zaretskii
  2020-07-01 19:20 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-07-01 19:21 ` Jakub Jankiewicz
  2020-07-01 19:21 ` Jakub Jankiewicz
  3 siblings, 0 replies; 10+ messages in thread
From: Jakub Jankiewicz @ 2020-07-01 19:21 UTC (permalink / raw)
  To: Greg Hill; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 848 bytes --]



On Wed, 1 Jul 2020 12:12:06 -0700
Greg Hill <gregoryohill@gmail.com> wrote:

> I've pretty well mastered the process of *writing to* a buffer using
> *insert* and *format*, but I haven't been able to find any equally easy way
> to read that same information back. I've hacked together a workaround using
> *copy-to-register*, *get-register* and *read-from-string*, but surely there
> must be a more straightforward approach than that. I've searched and
> searched through all the documentation and have come up with nothing for
> doing a simple formatted read from buffer. Any suggestions?

I was asking same question few years ago on StackOverlow:

[How to read contents of the file programmatically in Emacs?][1]

[1]: https://stackoverflow.com/a/34434144/387194


--
Jakub Jankiewicz, Web Developer
https://jcubic.pl/me

[-- Attachment #2: Podpis cyfrowy OpenPGP --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: Reading from a buffer
  2020-07-01 19:12 Reading from a buffer Greg Hill
                   ` (2 preceding siblings ...)
  2020-07-01 19:21 ` Jakub Jankiewicz
@ 2020-07-01 19:21 ` Jakub Jankiewicz
  3 siblings, 0 replies; 10+ messages in thread
From: Jakub Jankiewicz @ 2020-07-01 19:21 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 848 bytes --]



On Wed, 1 Jul 2020 12:12:06 -0700
Greg Hill <gregoryohill@gmail.com> wrote:

> I've pretty well mastered the process of *writing to* a buffer using
> *insert* and *format*, but I haven't been able to find any equally easy way
> to read that same information back. I've hacked together a workaround using
> *copy-to-register*, *get-register* and *read-from-string*, but surely there
> must be a more straightforward approach than that. I've searched and
> searched through all the documentation and have come up with nothing for
> doing a simple formatted read from buffer. Any suggestions?

I was asking same question few years ago on StackOverlow:

[How to read contents of the file programmatically in Emacs?][1]

[1]: https://stackoverflow.com/a/34434144/387194


--
Jakub Jankiewicz, Web Developer
https://jcubic.pl/me

[-- Attachment #2: Podpis cyfrowy OpenPGP --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: Reading from a buffer
@ 2020-07-01 20:19 Greg Hill
  2020-07-01 21:10 ` Stefan Monnier
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Greg Hill @ 2020-07-01 20:19 UTC (permalink / raw)
  To: help-gnu-emacs

The function 'buffer-substring-no-properties' is certainly a step in the
right direction, thank you. I've now got it down to:
(setq count (car (read-from-string (buffer-substring-no-properties (mark)
(point)))))
But I'm nothing short of astonished that there is not yet anything in
standard Emacs Lisp that is comparable to a formatted read-from-buffer
statement in a more conventional programming language like Fortran or C.
I'm imagining something akin to '(insert (format...' but working in the
opposite direction, something like '(unformat (read...'.  Perhaps I'll just
create my own library of intuitive and easy-to-use buffer I/O functions
since I expect to be doing quite a bit of this sort of thing in the future.


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

* Re: Reading from a buffer
  2020-07-01 20:19 Greg Hill
@ 2020-07-01 21:10 ` Stefan Monnier
  2020-07-02  0:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2020-07-03  3:38 ` Jean-Christophe Helary
  2 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2020-07-01 21:10 UTC (permalink / raw)
  To: help-gnu-emacs

> The function 'buffer-substring-no-properties' is certainly a step in the
> right direction, thank you. I've now got it down to:
> (setq count (car (read-from-string (buffer-substring-no-properties (mark)
> (point)))))
> But I'm nothing short of astonished that there is not yet anything in
> standard Emacs Lisp that is comparable to a formatted read-from-buffer
> statement in a more conventional programming language like Fortran or C.
> I'm imagining something akin to '(insert (format...' but working in the
> opposite direction, something like '(unformat (read...'.  Perhaps I'll just
> create my own library of intuitive and easy-to-use buffer I/O functions
> since I expect to be doing quite a bit of this sort of thing in the future.

Maybe you're looking for:

  looking-at or re-search-forward

followed by

  match-string

?


        Stefan




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

* Re: Reading from a buffer
  2020-07-01 20:19 Greg Hill
  2020-07-01 21:10 ` Stefan Monnier
@ 2020-07-02  0:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2020-07-03  3:38 ` Jean-Christophe Helary
  2 siblings, 0 replies; 10+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-07-02  0:39 UTC (permalink / raw)
  To: help-gnu-emacs

Greg Hill wrote:

> The function 'buffer-substring-no-properties' is
> certainly a step in the right direction, thank you.
> I've now got it down to: (setq count (car
> (read-from-string (buffer-substring-no-properties
> (mark) (point)))))

Glad to hear it, but I don't follow what you intend
to do?

> But I'm nothing short of astonished that there is
> not yet anything in standard Emacs Lisp that is
> comparable to a formatted read-from-buffer
> statement in a more conventional programming
> language like Fortran or C. I'm imagining something
> akin to '(insert (format...' but working in the
> opposite direction, something like '(unformat
> (read...'. Perhaps I'll just create my own library
> of intuitive and easy-to-use buffer I/O functions
> since I expect to be doing quite a bit of this sort
> of thing in the future.

Unformat the buffer? ... ?

Something like:

(how-many "[[:digit:]]") ; eight

(when (re-search-forward "[[:digit:]]+" (point-max) t)
  (message (format "found digit: %s" (match-string-no-properties 0)) ))

eval the above `when' to find...

256

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: Reading from a buffer
  2020-07-01 20:19 Greg Hill
  2020-07-01 21:10 ` Stefan Monnier
  2020-07-02  0:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-07-03  3:38 ` Jean-Christophe Helary
  2020-07-03  6:33   ` Greg Hill
  2 siblings, 1 reply; 10+ messages in thread
From: Jean-Christophe Helary @ 2020-07-03  3:38 UTC (permalink / raw)
  To: Greg Hill; +Cc: Help Gnu Emacs mailing list

As Jakub mentioned, did you check the f.el library ?

https://github.com/rejeep/f.el

> On Jul 2, 2020, at 5:19, Greg Hill <gregoryohill@gmail.com> wrote:
> 
> The function 'buffer-substring-no-properties' is certainly a step in the
> right direction, thank you. I've now got it down to:
> (setq count (car (read-from-string (buffer-substring-no-properties (mark)
> (point)))))
> But I'm nothing short of astonished that there is not yet anything in
> standard Emacs Lisp that is comparable to a formatted read-from-buffer
> statement in a more conventional programming language like Fortran or C.
> I'm imagining something akin to '(insert (format...' but working in the
> opposite direction, something like '(unformat (read...'.  Perhaps I'll just
> create my own library of intuitive and easy-to-use buffer I/O functions
> since I expect to be doing quite a bit of this sort of thing in the future.

-- 
Jean-Christophe Helary @brandelune
http://mac4translators.blogspot.com




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

* Re: Reading from a buffer
  2020-07-03  3:38 ` Jean-Christophe Helary
@ 2020-07-03  6:33   ` Greg Hill
  0 siblings, 0 replies; 10+ messages in thread
From: Greg Hill @ 2020-07-03  6:33 UTC (permalink / raw)
  To: Jean-Christophe Helary; +Cc: Help Gnu Emacs mailing list

Thank you, Jean-Christophe. I did take a look at the f.el library and
didn't see anything there that appears to be even remotely close to what
I'm looking for.  Since I'm just learning all this stuff for my own
amusement (70 years old, retired, and doing "brain exercises" to keep my
mind sharp) I really don't mind writing my own functions to do exactly what
I have in mind. In fact I have already written a first rough draft of what
will ultimately serve as documentation for it. Once I've written and
thoroughly debugged the code to implement it, I'll post a copy of the
documentation here on the help-gnu-emacs mailing list. I'll also send
copies of it wherever you folks suggest making it available to anyone who
might be interested in checking it out and maybe teaching me how to write
it more efficiently using tricks I haven't even discovered yet. Anyway, the
bottom line is, it doesn't really matter to me if I'm just re-inventing a
wheel that somebody else has already invented and made publicly available.

On Thu, Jul 2, 2020 at 8:38 PM Jean-Christophe Helary <
jean.christophe.helary@traduction-libre.org> wrote:

> As Jakub mentioned, did you check the f.el library ?
>
> https://github.com/rejeep/f.el
>
> > On Jul 2, 2020, at 5:19, Greg Hill <gregoryohill@gmail.com> wrote:
> >
> > The function 'buffer-substring-no-properties' is certainly a step in the
> > right direction, thank you. I've now got it down to:
> > (setq count (car (read-from-string (buffer-substring-no-properties (mark)
> > (point)))))
> > But I'm nothing short of astonished that there is not yet anything in
> > standard Emacs Lisp that is comparable to a formatted read-from-buffer
> > statement in a more conventional programming language like Fortran or C.
> > I'm imagining something akin to '(insert (format...' but working in the
> > opposite direction, something like '(unformat (read...'.  Perhaps I'll
> just
> > create my own library of intuitive and easy-to-use buffer I/O functions
> > since I expect to be doing quite a bit of this sort of thing in the
> future.
>
> --
> Jean-Christophe Helary @brandelune
> http://mac4translators.blogspot.com
>
>


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

end of thread, other threads:[~2020-07-03  6:33 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-01 19:12 Reading from a buffer Greg Hill
2020-07-01 19:19 ` Eli Zaretskii
2020-07-01 19:20 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-01 19:21 ` Jakub Jankiewicz
2020-07-01 19:21 ` Jakub Jankiewicz
  -- strict thread matches above, loose matches on Subject: below --
2020-07-01 20:19 Greg Hill
2020-07-01 21:10 ` Stefan Monnier
2020-07-02  0:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-03  3:38 ` Jean-Christophe Helary
2020-07-03  6:33   ` Greg Hill

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.