king@KESTREL.EDU (07/26/90)
>> For a long time, I've been thinking about writing a function in emacs >> that, taking a list of blank separated macro names that should be defined, >> carefully "hides" all code that falls between failing #ifdefs. Note that >> I am not suggesting that CPP be used, since that would have the undesirable >> side-effect of expanding all the other macros and generally uglifying the >> code when only "hiding" was desired. The following questions thus arise: >> >> 2. How would people suggest I "hide" sections of a buffer without physically >> deleting it? (I.E. you should be able to bring it all back exactly the >> way it was with a keystroke, toggling back and forth as often as desired). >> This may be an insurmountable problem, but I hope not. Perhaps deleting >> it would be OK as long as you could bring back all the deleted chunks >> at once when necessary. There are at least two interesting variables defined in emacs: selective-display's value is nil Documentation: t enables selective display: after a ^M, all the rest of the line is invisible. ^M's in the file are written into files as newlines. Integer n as value means display only lines that start with less than n columns of space. Automatically becomes local when set in any fashion. selective-display-ellipses's value is t Documentation: t means display ... on previous line when a line is invisible. Automatically becomes local when set in any fashion. This is what i would use. Pretending a macro is [un]defined would be done by putting a ^M at the beginnings of the #ifdef, #else, and #endif lines, as well as before each line that is not being used. As you can see from selective-display's documentation, the file gets written correctly even if some lines are rendered invisible by selective display. Do be careful to fix all of the ^M's before turning off selective-display, if you ever choose to do so. Also note that if you choose to use marks to keep track of where your ^M's are, be sure to axe them when they're no longer needed. If they pile up unmercifully the system will become more and more sluggish until the next garbage collection. You almost certainly want selective-display-ellipses to be nil. My ideal user interface would be M-X define-macros and M-X undefine-macros. The package should collect the names of all of the macros that appear in #if[n]def's and do completing reads. After reading each one it should The following code seems to work: (setq read-list ' (("aaa") ("bbb") ("ccc"))) ; a test list of macros ; that make sense locally ; you would compute this ; from the buffer. (defun define-macros (x) (interactive (let ((read-so-far ()) (going t)) (while going (let ((one-readee (completing-read (if read-so-far (format "things %s: " (mapconcat (function (lambda (x) x)) (reverse read-so-far) ", ")) "things: ") (cons '("") read-list) (function (lambda (x) (not (assoc x read-so-far)))) t))) (if (equal one-readee "") (setq going nil) (push one-readee read-so-far)))) (list read-so-far))) (print x)) . Hope this helps... -dk