[net.emacs] some GNUemacs C-mode routines

murf@caeco.uucp (Steve Murphy) (07/22/86)

Just for the heck of it, I've written several little routines,
some of which I share with the world here.

They are meant to be handy for those who program in C.
All they do is find matching braces. A set-mark is done
so you can return to your previous position quickly.

They are at times handy for me, and seem to work well.

find-matching brace is meant to work with the user parking
his cursor on the he wishes to find the match for, and executing
the routine.

The others are less picky about the cursor position.
------------------------------------------------------------------------
(defun find-matching-open-brace ()
  "set mark, look for opening brace for present block level"
  (interactive)
  (set-mark-command nil)
  (let ((levcount 1))
	(while (> levcount 0)
	  (if (re-search-backward "{\\|}" nil t)
		  (if (looking-at "{")
			  (setq levcount (1- levcount))
			(if (looking-at "}")
				(setq levcount (1+ levcount))))
		(setq levcount 0)))))
(defun find-matching-close-brace ()
  "set mark, look for closing brace for present block level"
  (interactive)
  (set-mark-command nil)
  (if (looking-at "{")
	  (forward-char))
  (let ((levcount 1))
	(while (> levcount 0)
	  (if (re-search-forward "{\\|}" nil t)
		  (progn (backward-char)
				 (if (looking-at "{")
					 (setq levcount (1+ levcount))
				   (if (looking-at "}")
					   (setq levcount (1- levcount))))
				 (forward-char))
		(exchange-point-and-mark)
		(setq levcount 0)))
	(backward-char)))
(defun find-matching-brace ()
  "find brace matching one after point, set mark and jump there"
  (interactive)
  (if (looking-at "{")
	  (find-matching-close-brace)
	(if (looking-at "}")
		(find-matching-open-brace))))

-----
"The above is purely fictional--any resemblance to fact should
		be attributed to Coincidence."

	Steve Murphy, 	CAECO, Inc., 1160 S. State Str.
			Suite 280, Orem, UT 84058
			
	<WORLD>!seismo!utah-gr!uplherc!wicat!caeco!{steve,murf}
	<WORLD>!akgua!byuadam!caeco!______________/
		(byuadam is on the arpanet,too)
-- 
-----
"The above is purely fictional--any resemblance to fact should
		be attributed to Coincidence."

	Steve Murphy, 	CAECO, Inc., 1160 S. State Str.
			Suite 280, Orem, UT 84058
			
	<WORLD>!seismo!utah-gr!uplherc!wicat!caeco!{steve,murf}
	<WORLD>!akgua!byuadam!caeco!______________/
		(byuadam is on the arpanet,too)