20070830

I like emacs.

Here's some emacs lisp I whipped up yesterday. It helps out when running quilt against new .spec files on old systems. It's a bit crude, but so far it's proven quite the little timesaver -- it's certainly already repaid the 10 minutes I put into writing it.



;; Temporarily comment out %gconf_schemas_prereq, %lang_package,
;; %files lang, etc.
;; Useful when using quilt setup. Don't forget to save. You can
;; undo this with M-x ab-undumb-down-spec.
(require 'cl)
(setf replacements '(("^%gconf_schemas_prereq"
"# GCONF_SCHEMAS_PREREQ"
"%gconf_schemas_prereq")
("^%lang_package"
"# LANG_PACKAGE"
"%lang_package")
("^%files lang"
"# FILES LANG" "%files lang")
("^gnome-patch-translation-prepare"
"# GNOME-PATCH-TRANSLATION-PREPARE"
"gnome-patch-translation-prepare")
("^gnome-patch-translation-update"
"# GNOME-PATCH-TRANSLATION-UPDATE"
"gnome-patch-translation-update")))

(defun ab-dumb-down-spec ()
(interactive)
(let ((old-pnt (point-marker)))
(progn (mapcar (lambda (arg)
(progn (beginning-of-buffer)
(replace-regexp (first arg) (second arg))))
replacements)
(goto-char old-pnt))))

(defun ab-undumb-down-spec ()
(interactive)
(let ((old-pnt (point-marker)))
(progn (mapcar (lambda (arg)
(progn (beginning-of-buffer)
(replace-string (second arg) (third arg))))
replacements)
(goto-char old-pnt))))



Adding new pieces of text to replace and unreplace is easy: add a list containing a regular expression matching the text to destroy, a(n ideally) unique temporary replacement, and the original text to replacements. I use a regexp in the cars in case there's the same text elsewhere, which I wouldn't want to change.

Now I visit a .spec file, run M-x ab-dumb-down-spec, do quilt setup whatever.spec and other quilty things, and then revisit the .spec and do M-x ab-undumb-down-spec prior to doing actual builds.

(By the way, the meat of this post was created by setting a region around this chunk of lisp and running M-x htmlize, although it looks like blogger is eating the colors.)

No comments: