2009-10-11

elisp text processing: disable undo, etc

On Oct 10, 6:49 pm, Decebal wrote:
> I am doing a lot of work on a big buffer (65 MB). I understood that
> there is a possibility to disable the undo functionality. Something
> that is not used in batch-mode. So this could give a performance
> boost.
> How can I disable undo?
> Are there other things that could be usefull performance wise?

buffer-disable-undo

you find it by calling “elisp-index-search” with search word “undo”.

for batch processing, you want to disable undo, also turn off syntax coloring, possibly turn off auto save, auto back up, ...etc.

best do it with temp buffer

e.g.

(defun my-process-file (fpath)
"Process the file at path FPATH ..."
(let ()
;; create temp buffer without undo record.
;; first space in temp buff name is necessary
(set-buffer (get-buffer-create " myTemp"))
(insert-file-contents fpath nil nil nil t)

;; process it ...
;; (goto-char 0) ; move to begining of file's content
;; ...
;; (write-file fpath) ;; write back to the file

(kill-buffer " myTemp")))

or use with-temp-buffer or with-temp-file.

for more tips on using elisp as a text processing lang like perl, python, see:

• Text Processing with Emacs Lisp
http://xahlee.org/emacs/elisp_idioms_batch.html

Xah
∑ http://xahlee.org/

No comments:

Post a Comment