unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* map-file-lines
@ 2009-02-02 17:20 Ted Zlatanov
  2009-02-02 18:54 ` map-file-lines Stefan Monnier
  2009-02-02 20:48 ` map-file-lines Ted Zlatanov
  0 siblings, 2 replies; 50+ messages in thread
From: Ted Zlatanov @ 2009-02-02 17:20 UTC (permalink / raw)
  To: emacs-devel

Emacs Lisp lacks a good way to iterate over all the lines of a file,
especially for a large file.  The following code tries to provide a
solution, concentrating on reading a block of data in one shot and then
processing it line by line.  It may be more efficient to write this in
C.  Also, it does not deal with cases where the first line read is
bigger than the buffer size, and may have other bugs, but it works for
me so I thought I'd post it for comments and criticism.

Thanks
Ted

(defun map-file-lines (file func &optional bufsize)
  (let ((filepos 0)
	(linenum 0)
	(bufsize (or bufsize 4096)))
    (with-temp-buffer
      (while
	  (let*
	      ((inserted (insert-file-contents
			  file nil
			  filepos (+ filepos bufsize) 
			  t))
	       (numlines (count-lines (point-min) (point-max)))
	       (read (nth 1 inserted))
	       (done (< 1 read)))
	    (dotimes (n (count-lines (point-min) (point-max)))
		(goto-char (point-min))
		(funcall func 
			 (buffer-substring 
			  (line-beginning-position) 
			  (line-end-position)) 
			 (incf linenum))
		(incf filepos (line-end-position))
		(forward-line))
	    done)))
    linenum))

;;(map-file-lines "/tmp/test" (lambda (line num) (message "%d: %s" line)))





^ permalink raw reply	[flat|nested] 50+ messages in thread
* view/edit large files (was: map-file-lines)
@ 2009-02-07  3:44 MON KEY
  2009-02-08  4:34 ` Bob Rogers
  0 siblings, 1 reply; 50+ messages in thread
From: MON KEY @ 2009-02-07  3:44 UTC (permalink / raw)
  To: tzz; +Cc: emacs-devel

> [1] I still can't think of a better term than "window."
> large-file-window is too verbose.  boffset?  byte-offset?
> virtual-buffer?

off-slice
slice-off
virtual-slice

s_P




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

end of thread, other threads:[~2009-02-20 19:23 UTC | newest]

Thread overview: 50+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-02 17:20 map-file-lines Ted Zlatanov
2009-02-02 18:54 ` map-file-lines Stefan Monnier
2009-02-02 19:22   ` map-file-lines Ted Zlatanov
2009-02-02 19:52     ` map-file-lines joakim
2009-02-02 20:54       ` map-file-lines Ted Zlatanov
2009-02-02 22:42         ` map-file-lines Stefan Monnier
2009-02-03 13:57           ` map-file-lines Ted Zlatanov
2009-02-02 22:41       ` map-file-lines Stefan Monnier
2009-02-02 23:59         ` map-file-lines joakim
2009-02-03  4:13           ` map-file-lines Stefan Monnier
2009-02-03  7:27             ` map-file-lines joakim
2009-02-03 14:50               ` map-file-lines Stefan Monnier
2009-02-04  7:04                 ` map-file-lines Richard M Stallman
2009-02-04 15:38                   ` map-file-lines Ted Zlatanov
2009-02-05  5:40                     ` map-file-lines Richard M Stallman
2009-02-06 18:42                       ` view/edit large files (was: map-file-lines) Ted Zlatanov
2009-02-06 21:06                         ` view/edit large files Ted Zlatanov
2009-02-06 21:49                           ` Miles Bader
     [not found]                             ` <864oz3nyj8.fsf@lifelogs.com>
2009-02-10  1:58                               ` Stefan Monnier
2009-02-10  8:46                                 ` Eli Zaretskii
2009-02-10  9:23                                   ` Miles Bader
2009-02-10  9:54                                     ` Eli Zaretskii
2009-02-10 10:02                                       ` Miles Bader
2009-02-10 11:50                                         ` Eli Zaretskii
2009-02-10 15:08                                           ` Ted Zlatanov
2009-02-17 19:23                                             ` Stefan Monnier
2009-02-17 19:47                                               ` Eli Zaretskii
2009-02-17 20:18                                                 ` Miles Bader
2009-02-17 20:51                                                   ` Eli Zaretskii
2009-02-17 21:19                                                     ` Miles Bader
2009-02-17 21:21                                                       ` Miles Bader
2009-02-18  4:09                                                         ` Eli Zaretskii
2009-02-18  1:56                                                 ` Stefan Monnier
2009-02-20 19:23                                                   ` Ted Zlatanov
2009-02-10 12:28                                     ` Eli Zaretskii
2009-02-10 12:46                                       ` Miles Bader
2009-02-07  9:14                         ` view/edit large files (was: map-file-lines) Richard M Stallman
2009-02-09 20:26                           ` view/edit large files Ted Zlatanov
2009-02-10 20:02                             ` Richard M Stallman
2009-02-06 13:20                 ` map-file-lines Mathias Dahl
2009-02-02 22:40     ` map-file-lines Stefan Monnier
2009-02-03  4:11       ` map-file-lines Stefan Monnier
2009-02-02 20:48 ` map-file-lines Ted Zlatanov
2009-02-03  8:08   ` map-file-lines Thien-Thi Nguyen
2009-02-03 14:00     ` map-file-lines Ted Zlatanov
2009-02-03 14:17       ` map-file-lines Miles Bader
2009-02-03 10:45   ` map-file-lines Thierry Volpiatto
2009-02-03 14:06     ` map-file-lines Ted Zlatanov
2009-02-03 14:56       ` map-file-lines Thierry Volpiatto
  -- strict thread matches above, loose matches on Subject: below --
2009-02-07  3:44 view/edit large files (was: map-file-lines) MON KEY
2009-02-08  4:34 ` Bob Rogers
2009-02-09 19:44   ` view/edit large files Thien-Thi Nguyen

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).