all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Reading file in emacs
@ 2010-06-23  4:05 Qiang Guo
  2010-06-23  5:11 ` Dirk-Jan C. Binnema
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Qiang Guo @ 2010-06-23  4:05 UTC (permalink / raw)
  To: Emacs mailing list

Hi,

I'm wondering if there is a way to read the content of files, say, to a
variable rather than a buffer ? Of course, one way to do
this is first read file into buffer and then edit the
buffer. Here comes my second question, how to process file
in a byte-by-byte fashion, for instance, instead of editing
a line of text, I'd like to edit directly their binary
representations ?

I know this is best done by C/C++, or some other
languages. However, I just wonder the possibility of doing
this in emacs, the greatest editor ever :-)

Thanks

Qiang



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

* Re: Reading file in emacs
  2010-06-23  4:05 Reading file in emacs Qiang Guo
@ 2010-06-23  5:11 ` Dirk-Jan C. Binnema
  2010-06-23  5:13 ` Dirk-Jan C. Binnema
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Dirk-Jan C. Binnema @ 2010-06-23  5:11 UTC (permalink / raw)
  To: Qiang Guo; +Cc: Emacs mailing list

>>>>> On Tue, 22 Jun 2010 22:05:18 -0600, Qiang Guo ("QG") wrote:

  QG> Hi,
  QG> I'm wondering if there is a way to read the content of files, say, to a
  QG> variable rather than a buffer ? Of course, one way to do
  QG> this is first read file into buffer and then edit the
  QG> buffer. Here comes my second question, how to process file
  QG> in a byte-by-byte fashion, for instance, instead of editing
  QG> a line of text, I'd like to edit directly their binary
  QG> representations ?

I'd bet there are more elegant (elispy) ways to do this, but to read a file
into a variable, you could do something like:

    (setq filedata (shell-command-to-string "cat /foo/bar/myfile"))
    
Best wishes,
Dirk.

-- 
Dirk-Jan C. Binnema                  Helsinki, Finland
e:djcb@djcbsoftware.nl           w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C



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

* Re: Reading file in emacs
  2010-06-23  4:05 Reading file in emacs Qiang Guo
  2010-06-23  5:11 ` Dirk-Jan C. Binnema
@ 2010-06-23  5:13 ` Dirk-Jan C. Binnema
  2010-06-23  6:38 ` Kevin Rodgers
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Dirk-Jan C. Binnema @ 2010-06-23  5:13 UTC (permalink / raw)
  To: Emacs mailing list

>>>>> On Tue, 22 Jun 2010 22:05:18 -0600, Qiang Guo ("QG") wrote:

  QG> Hi,
  QG> I'm wondering if there is a way to read the content of files, say, to a
  QG> variable rather than a buffer ? Of course, one way to do
  QG> this is first read file into buffer and then edit the
  QG> buffer. Here comes my second question, how to process file
  QG> in a byte-by-byte fashion, for instance, instead of editing
  QG> a line of text, I'd like to edit directly their binary
  QG> representations ?

I'd bet there are more elegant (elispy) ways to do this, but to read a file
into a variable, you could do something like:

    (setq filedata (shell-command-to-string "cat /foo/bar/myfile"))
    
Best wishes,
Dirk.

-- 
Dirk-Jan C. Binnema                  Helsinki, Finland
e:djcb@djcbsoftware.nl           w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C



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

* Re: Reading file in emacs
  2010-06-23  4:05 Reading file in emacs Qiang Guo
  2010-06-23  5:11 ` Dirk-Jan C. Binnema
  2010-06-23  5:13 ` Dirk-Jan C. Binnema
@ 2010-06-23  6:38 ` Kevin Rodgers
  2010-06-23 11:28 ` Deniz Dogan
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Kevin Rodgers @ 2010-06-23  6:38 UTC (permalink / raw)
  To: help-gnu-emacs

Qiang Guo wrote:

> I'm wondering if there is a way to read the content of files, say, to a
> variable rather than a buffer ? Of course, one way to do
> this is first read file into buffer and then edit the
> buffer.

That is the best way to do it.  To get the content into a variable:

(let ((file-content (with-temp-buffer
		      (insert-file-contents "/path/to/file.txt")
		      (buffer-string))))
   ...
)

? Here comes my second question, how to process file
> in a byte-by-byte fashion, for instance, instead of editing
> a line of text, I'd like to edit directly their binary
> representations ?

Use insert-file-contents-literally above.

> I know this is best done by C/C++, or some other
> languages. However, I just wonder the possibility of doing
> this in emacs, the greatest editor ever :-)

The best tool for a job also depends on the craftsman using it.  For me
it is Emacs, not C/C++.

-- 
Kevin Rodgers
Denver, Colorado, USA




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

* Re: Reading file in emacs
       [not found] <mailman.0.1277266011.21451.help-gnu-emacs@gnu.org>
@ 2010-06-23  9:05 ` John McCabe
  0 siblings, 0 replies; 10+ messages in thread
From: John McCabe @ 2010-06-23  9:05 UTC (permalink / raw)
  To: help-gnu-emacs

On Tue, 22 Jun 2010 22:05:18 -0600, Qiang Guo <mcknight0219@gmail.com>
wrote:

>Here comes my second question, how to process file
>in a byte-by-byte fashion, for instance, instead of editing
>a line of text, I'd like to edit directly their binary
>representations ?

M-x hexl-mode

Does that help?



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

* Re: Reading file in emacs
  2010-06-23  4:05 Reading file in emacs Qiang Guo
                   ` (2 preceding siblings ...)
  2010-06-23  6:38 ` Kevin Rodgers
@ 2010-06-23 11:28 ` Deniz Dogan
  2010-06-23 14:38 ` Gary
       [not found] ` <mailman.4.1277292530.15366.help-gnu-emacs@gnu.org>
  5 siblings, 0 replies; 10+ messages in thread
From: Deniz Dogan @ 2010-06-23 11:28 UTC (permalink / raw)
  To: Qiang Guo; +Cc: Emacs mailing list

2010/6/23 Qiang Guo <mcknight0219@gmail.com>:
> I know this is best done by C/C++, or some other
> languages. However, I just wonder the possibility of doing
> this in emacs, the greatest editor ever :-)
>

C and C++ - the best programming languages for reading files.

-- 
Deniz Dogan



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

* Re: Reading file in emacs
  2010-06-23  4:05 Reading file in emacs Qiang Guo
                   ` (3 preceding siblings ...)
  2010-06-23 11:28 ` Deniz Dogan
@ 2010-06-23 14:38 ` Gary
       [not found] ` <mailman.4.1277292530.15366.help-gnu-emacs@gnu.org>
  5 siblings, 0 replies; 10+ messages in thread
From: Gary @ 2010-06-23 14:38 UTC (permalink / raw)
  To: help-gnu-emacs

Qiang Gu writes:

> Here comes my second question, how to process file
> in a byte-by-byte fashion, for instance, instead of editing
> a line of text, I'd like to edit directly their binary
> representations ?

I don't know about binary, but try M-x hexl-(and then press the TAB key,
you should get a couple of meaningful possibilities, depending on
whether you want to change the current buffer's mode or open/visit a
file using hex editor mode.




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

* Re: Reading file in emacs
       [not found] ` <mailman.4.1277292530.15366.help-gnu-emacs@gnu.org>
@ 2010-06-24 10:26   ` Pascal J. Bourguignon
  2010-06-24 11:20     ` Andreas Politz
  0 siblings, 1 reply; 10+ messages in thread
From: Pascal J. Bourguignon @ 2010-06-24 10:26 UTC (permalink / raw)
  To: help-gnu-emacs

Deniz Dogan <deniz.a.m.dogan@gmail.com> writes:

> 2010/6/23 Qiang Guo <mcknight0219@gmail.com>:
>> I know this is best done by C/C++, or some other
>> languages. However, I just wonder the possibility of doing
>> this in emacs, the greatest editor ever :-)
>>
>
> C and C++ - the best programming languages for reading files.

No.  There is no operator defined in C to read files.  (You have to use
an external library, such as a unix kernel or a POSIX library).

In the case of C++ there is some standard library defined, but not to
read files, just to read sequences of bytes.  So you could argue that
it as some worth for that, but my files are very rarely sequences of
bytes...



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


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

* Re: Reading file in emacs
  2010-06-24 10:26   ` Pascal J. Bourguignon
@ 2010-06-24 11:20     ` Andreas Politz
  2010-06-24 11:50       ` Pascal J. Bourguignon
  0 siblings, 1 reply; 10+ messages in thread
From: Andreas Politz @ 2010-06-24 11:20 UTC (permalink / raw)
  To: help-gnu-emacs

pjb@informatimago.com (Pascal J. Bourguignon) writes:

> Deniz Dogan <deniz.a.m.dogan@gmail.com> writes:
>
>> 2010/6/23 Qiang Guo <mcknight0219@gmail.com>:
>>> I know this is best done by C/C++, or some other
>>> languages. However, I just wonder the possibility of doing
>>> this in emacs, the greatest editor ever :-)
>>>
>>
>> C and C++ - the best programming languages for reading files.
>
> No.  There is no operator defined in C to read files.  (You have to use
> an external library, such as a unix kernel or a POSIX library).
>
> In the case of C++ there is some standard library defined, but not to
> read files, just to read sequences of bytes.  So you could argue that
> it as some worth for that, but my files are very rarely sequences of
> bytes...

I think you missed the irony.

-ap


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

* Re: Reading file in emacs
  2010-06-24 11:20     ` Andreas Politz
@ 2010-06-24 11:50       ` Pascal J. Bourguignon
  0 siblings, 0 replies; 10+ messages in thread
From: Pascal J. Bourguignon @ 2010-06-24 11:50 UTC (permalink / raw)
  To: help-gnu-emacs

Andreas Politz <politza@fh-trier.de> writes:

> pjb@informatimago.com (Pascal J. Bourguignon) writes:
>
>> Deniz Dogan <deniz.a.m.dogan@gmail.com> writes:
>>
>>> 2010/6/23 Qiang Guo <mcknight0219@gmail.com>:
>>>> I know this is best done by C/C++, or some other
>>>> languages. However, I just wonder the possibility of doing
>>>> this in emacs, the greatest editor ever :-)
>>>>
>>>
>>> C and C++ - the best programming languages for reading files.
>>
>> No.  There is no operator defined in C to read files.  (You have to use
>> an external library, such as a unix kernel or a POSIX library).
>>
>> In the case of C++ there is some standard library defined, but not to
>> read files, just to read sequences of bytes.  So you could argue that
>> it as some worth for that, but my files are very rarely sequences of
>> bytes...
>
> I think you missed the irony.

Probably :-/   But a lot of people think it's true...


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


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

end of thread, other threads:[~2010-06-24 11:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-23  4:05 Reading file in emacs Qiang Guo
2010-06-23  5:11 ` Dirk-Jan C. Binnema
2010-06-23  5:13 ` Dirk-Jan C. Binnema
2010-06-23  6:38 ` Kevin Rodgers
2010-06-23 11:28 ` Deniz Dogan
2010-06-23 14:38 ` Gary
     [not found] ` <mailman.4.1277292530.15366.help-gnu-emacs@gnu.org>
2010-06-24 10:26   ` Pascal J. Bourguignon
2010-06-24 11:20     ` Andreas Politz
2010-06-24 11:50       ` Pascal J. Bourguignon
     [not found] <mailman.0.1277266011.21451.help-gnu-emacs@gnu.org>
2010-06-23  9:05 ` John McCabe

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.