--- lgc-examples.el.orig 2003-12-02 22:25:37.000000000 +0000 +++ lgc-examples.el 2003-12-03 10:58:58.000000000 +0000 @@ -23,7 +23,7 @@ ;;; Code: ;;; MAGIC -(defconst lgc-c-section-regexp +(defvar lgc-c-section-regexp "^@unnumberedsubsubsec[[:blank:]]+\\([[:graph:]]+?\\.[ch]\\)" "Regexp for what comes before each complete C example. This should not include the @smallexample and @group, if present. The @@ -32,24 +32,24 @@ The first match group MUST be the file name to which the example shall be written.") -(defconst lgc-example-begin-regexp +(defvar lgc-example-begin-regexp "^@\\(?:small\\)?example\n+\\(?:@group\n+\\)?" "Regexp for beginning of an example.") -(defconst lgc-example-end-regexp +(defvar lgc-example-end-regexp "^\\(?:@end group\n+\\)?@end \\(?:small\\)?example") -(defconst lgc-c-output-dir +(defvar lgc-c-output-dir "examples" "Directory in which to place example C files and Makefile for them. May be either absolute, or relative to the source Texinfo file.") -(defconst lgc-c-makeable-regexp "\.c$" +(defvar lgc-c-makeable-regexp "\.c$" "Regexp to recognize whether or not to make an executable.") ;;; Don't forget to update the other two list members if you change ;;; the template text! -(defconst lgc-c-makefile-template +(defvar lgc-c-makefile-template '("## Makefile for examples in `Learning GNU C' ## Generated by lgc-examples.el from the Texinfo source @@ -86,7 +86,7 @@ ;;; Keep compile from complaining; normally, this is only set ;;; dynamically by anyone who wants to use lgc-add-makefile-entry. -(eval-when-compile (defconst lgc-lame-init nil)) +(eval-when-compile (defvar lgc-lame-init nil)) ;;; COMMANDS (defun lgc-snarf-examples (&optional beg end) @@ -106,6 +106,8 @@ "Debug the callback arguments from `lgc-apply-examples'. DEBUGBUF, interactively prompted, is the buffer in which to write." (interactive "BParsing forms output buffer: ") + ;; I think B gets a string, not a buffer + (when (stringp debugbuf) (setq debugbuf (get-buffer-create debugbuf))) (save-excursion (set-buffer debugbuf) (erase-buffer)) (message "Parsed %d examples" (lgc-apply-examples (point-min) (point-max) @@ -119,7 +121,7 @@ (insert "\ntxibeg: ") (print txibeg (current-buffer)) (insert ?\n))) - ))) + 'lgc-nullify-txibeg))) ;;; PARSING DRIVER (defun lgc-apply-examples (beg end &rest funcs) @@ -133,7 +135,11 @@ file, and TXIBEG is a marker for the beginning of FBODY in the Texinfo file, suitable for computing the position and filename. -Return the number of examples processed." +Return the number of examples processed. + +Important: I recommend adding `lgc-nullify-txibeg' to the end of any +list of FUNCS you may use, if and only if you don't save any TXIBEGs +in your other FUNCS." (goto-char beg) (let ((example-count 0)) ;; loop until any search-failed @@ -217,7 +223,9 @@ * Marker at which to write make rules for said output, two newlines after each one. -Both markers have insertion type t." +Both markers have insertion type t. Bind the list to `lgc-lame-init' +for every dynamic context in which you build a makefile with repeated +calls to `lgc-add-makefile-entry'." (save-excursion (find-file (expand-file-name "Makefile" (expand-file-name lgc-c-output-dir))) @@ -240,7 +248,9 @@ ;;; MISC UTIL (defun lgc-nullify-txibeg (fname fbody txibeg) - "Point marker TXIBEG at nothing." + "Point marker TXIBEG at nothing. +This should be the last argument to `lgc-apply-examples', unless one +of your other functions ever saves a value of TXIBEG." (set-marker txibeg nil)) ;;; lgc-examples.el ends here