Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!ptsfa!lll-tis!mordor!sri-spam!rutgers!topaz.rutgers.edu!gaynor From: gaynor@topaz.rutgers.edu (Silver) Newsgroups: comp.emacs Subject: Re: Hiding comments in C mode Message-ID: <17561@topaz.rutgers.edu> Date: 23 Jan 88 16:33:37 GMT References: <8801202039.AA09434@ucbvax.Berkeley.EDU> <296@dana.UUCP> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 68 Check out outline-mode, and see if it's capable of doing what you want. I think that if you define outline-regexp carefully, you might just pull it off, and then you'll have a lot of functionality. Otherwise, I've just this minute written two-minute commands that make use the selective-display feature. I make no guarantees on this code. I didn't test them but for 2 minutes or so, neither do I intend to do anything with them at all. Make sure to set selective-display t in your c-mode-hook or something. They're still a little frazzled around the edges, magic numbers and all that rot. To be honest, I wonder at the original request. You want to hide the comments, and not the code? Are they especially rude and offensive, or do I just not seeing the reasoning? ___ \o/ Cheers, V [Ag] _|_ LOOKING FOR ENTRY-LEVELISH C/LISP PROGRAMMING, SOFTWARE ENGINEERING Andy Gaynor 201-545-0458 81 Hassart St, New Brunswick, NJ 08901 gaynor@topaz.rutgers.edu ...!rutgers!topaz.rutgers.edu!gaynor "There is no Editor but Emacs, and Lisp is its Prophet." ---------------------------------------------------------------------- (defun c-hide-comment () "Hide the current or next comment. Inserts 2 C-m's, so don't save it hidden. Leaves point beyond comment." (interactive) (let (begin end) (re-search-forward "[^\C-m]/\\*\\|[^\C-m]\\*/") (if (equal (preceding-char) ?*) (progn (setq begin (1+ (match-beginning 0))) (re-search-forward "[^\C-m]\\*/") (setq end (point))) (progn (setq end (match-end 0)) (re-search-backward "[^\C-m]/\\*") (setq begin (1+ (point))))) (goto-char begin) (insert "\C-m") (goto-char (1- end)) (insert "\C-m") (subst-char-in-region begin end ?\n ?\C-m t) (goto-char (+ 2 end)))) (defun c-show-comment () "Show the next hidden comment. Removes the C-m's inserted by c-hide-comment. Leaves point beyond comment." (interactive) (let (begin end) (re-search-forward "\C-m/\\*\\|\C-m\\*/") (if (equal (preceding-char) ?*) (progn (setq begin (match-beginning 0)) (re-search-forward "\C-m\\*/") (setq end (point))) (progn (setq end (match-end 0)) (re-search-backward "\C-m/\\*") (setq begin (point)))) (goto-char begin) (delete-char 1 nil) (goto-char (- end 4)) (delete-char 1 nil) (subst-char-in-region begin end ?\C-m ?\n t) (goto-char (1- end))))