>>>> "Stephen" == Stephen J Turnbull
Uwe Brauer writes:
> My first intent was something like this.
> (defun my-insert-counter-value ()
> (goto-char (point-max))
> (search-backward ";;; counter-value:")
> (beginning-of-line 1)
> (search-forward ";;; counter-value:")
> (insert (concat " " (format "%d" counter-value) " "))))
I would do it this way:
(defun my-insert-counter-value ()
;; Is there a Local variables section?
;; This "t" is what allows you to use a search as a
;; Boolean expression.
(let* ((prefix (match-string 1))
(suffix (match-string 2))
(end-re (format "^%s\\s-*End:\\s-*%s$" suffix prefix))
(my-re (format "^%s\\s-*counter-value:\\s-*%s$" suffix prefix))
;; Search limit "coming back" from End:
;; Check for syntactic validity of variables section
(if (not (re-search-forward end-re nil t))
;; You do want this to be an error; if it occurs, the
;; Local variables section will be ignored, and you'll
;; probably not know why!
(error 'invalid-state "Ill-formed Local variables section!")
;; Now go "back" to your variable.
;; #### This may be off-by-one if the counter-value line
;; #### isn't there yet. (If so, do `(forward-line 1)' here.)
(when (re-search-backward my-re here t)
;; #### `kill-entire-line' may be 21.5-only.
(insert (format "%s counter-value: %d %s\n"
prefix counter-value suffix))))))))
Thanks that is much more elegant then the solution I found meanwhile:
(defun footnote-addons-local-var ()
;; Heavy borrowings from hack-local-variables here.
"Set up the local variables for writing, or not.
Returns (prefix . suffix) for write."
(let ((lv-string (concat "Local " "Variables:")) (prefix
"") (suffix "")
(case-fold-search t) (xtra "") preflen ends haspref)
;; hack to avoid this looking like a real local variables entry
(max (- (point-max) 3000) (point-min)) 'move)
(if (search-forward lv-string nil 1)
I don't know why but putting it in the
kill-buffer-hook caused problems so I think the write-file-hooks is
XEmacs-Beta mailing list