help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

--batch on many files without reloading config (was: Re: hook syntax)


From: Emanuel Berg
Subject: --batch on many files without reloading config (was: Re: hook syntax)
Date: Tue, 05 May 2015 04:07:16 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> However, I have many (10-20) hooks set like this:
>> (setq perl-mode-hook 'enable-line-mode)
>
> Please just don't.

OK. But is it still OK with setq and a list?

By the way, perhaps this is something the compiler
should warn about?

I took this opportunity to try to do something cool,
namely to use the Emacs --batch gear to operate on
a set of files, but *without* having to reload the
configuration each time (for each file), which is the
case if one does a shell (bash, zsh) loop with the -u
option, and it just kills speed if you have just
a couple of files.

This turned out a bit more complicated than at first
sight. I was trying to save time :)

    ;; This file: http://user.it.uu.se/~embe8573/conf/emacs-init/batch.el

    ;; emacs --batch -u USER **/*.el -f fix-hooks-in-batch-args

    (require 'cl-macs)

    (defun fix-hooks ()
      (while (re-search-forward
              "(setq \\(.*\\)-hook\\([[:blank:]]*\\)'\\([^(].*\\))"
              nil ; no BOUND
              t)  ; NOERROR
        (replace-match "(setq \\1-hook\\2'(\\3))") )
      (when (buffer-modified-p) (save-buffer)) )

    (defun fix-hooks-in-batch-args ()
      (cl-dolist (file-rel (cdr command-line-args))  ; drop initial 'emacs'
        (let ((file (concat command-line-default-directory file-rel)))
          (when (file-exists-p file)                 ; drop options and 
'fix-hooks'
            (find-file file)                         ; - better way to filter 
files?
            (fix-hooks) ))))

-- 
underground experts united
http://user.it.uu.se/~embe8573


reply via email to

[Prev in Thread] Current Thread [Next in Thread]