File:  [Research Unix] / researchv9 / cmd / emacs / macros / olisp
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:59 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv9-SUN3_old, researchv9-SUN3, HEAD
researchv9-SUN3(old)

)		Electric C ) - Show matching parens - [if lnowid >= 4]

C. Douglas Blewett (MH3-C-319) Version 4.3

This file contains assorted macros to make life more livable while
working with LISP and C.  The routines attached to ) and } are a
little smarter than "balance" about showing matches that are off the
screen.  M-% goes to the matching paren or brace.  If the cursor is
on a "(" the routine will find the corresponding ")" (or "{" and "}").
Of course, if the cursor is on a ")" or a "}" the routine will find the
matching "(" or "{".  C mode MUST be turned OFF for this stuff to work.

At Jeff Langer's suggestion "}" also adjusts the indentation to that
found on the line containing the matching "{".

The routine attached to ^M (carriage return) indents correctly
(maintains the level of indentation including spaces and tabs) and
removes unused white space (usually caused by the indenting routine
itself) on blank lines.

WARNING: this routine uses "comcol" and "lnowid" as global variables for
storing the current level of indentation and turning these features on
and off (High Voltage).

 Interface routines
	M-%  - Moves to corresponding () or {} pair (like vi % command)
	)    - Shows matching "(" (only if it is currently displayed)
	{    - Inserts {, a ^M and indents one tab
	}    - Shows matching "{" (only if it is currently displayed)
	^M   - Maintains the exact level of indentation and removes
		unused whitespace from interveneing empty lines
	;    - Inserts a ; and does a ^M
	M-^^ - Toggles these features (High Voltage) on and off

	)
	<lnowid
	�
<lnowid
	

	|�
		�5~4
			��
			�On_screen
			
		�
	�

�	Electric C Level - [lnowid >= 4 ^M and ), >= 5 }, >= 6 { and ;]
	<c
	
				Turn of C mode
	<comcol
	0
				Set indent to zero
	<lnowid
	�
<lnowid
	|�
		�~4
			4

			0<High Voltage Electric C On Low - 4
		�
		�~5
			5

			0<High Voltage Electric C On Medium - 5
		�
		�~6
			6

			0<High Voltage Electric C On High - 6
		�
		� 
			3

			0<High Voltage Electric C off
		�
	�

;		Electric C ; - New line and indent - [if lnowid >= 6]
	;
	<lnowid
	�
<lnowid
	

	|�
		�5~6
			

		�
	�

{		Electric C { - New line and indent - [if lnowid >= 6]
	{
	<lnowid
	�
<lnowid
	

	|�
		�5~6
			�Indent_get
				-
		�
	�

}		Electric C } - Match Previous, etc. - [if lnowid >= 5]
	}
	<lnowid
	�
<lnowid
	

	|�
		�5~5
			<-
			��
			�On_screen
			�Indent_get
			5��Indent_get
			--<}<-
			�3-}�
		�
	�

�On_screen
	|�			Test if it is on the screen
		�~3=-1
		�
		� 
			#8�80--
			80
		�	Quick Twitch - it is faster than a 1 sec. delay
	�

�Indent_get
	�1				Copy the indentation
	<
	^�4~0
		!�
			� 
				+
			�
			�	
				+
			�
			��
				�0
			�
		�
	�

�		Find_Matching parens and braces
	!�			What are we matching
		�(
			�1
			5�1
			6�4
			<[()]
		�
		�)
			�-1
			5�-1
			6�-4
			<[()]
		�
		�{
			�1
			5�1
			6�4
			<[{}]
		�
		�}
			�-1
			5�-1
			6�-4
			<[{}]
		�
		��
			�0
			
		�
	�
	^�4~0		Loop until match is found
		|�
			�5		Move off the  current item
				0>	Get a copy of the search string
				6�	Search in the correct direction
				!�	What we found
					�(
						�11~1
					�
					�)
						�11~-1
					�
					�{
						�11~1
					�
					�}
						�11~-1
					�
					��
						�0
					�
				�
			�
			� 		Beginning or end of file
				�0
			�
		�
		|�		Kludge to handle loop bug
			�1~0
				|�
					�~50
						5�0
						-
					�
				�
			�
		�
	�


		Electric C - Maintain the indent - [if lnowid >= 4]
	
	<lnowid
	�
<lnowid
	

	|�
		�5~4
	|�
		�
			�1	^U is the flag for space or tabs loop
			6�0	6 is the flag for line containing chars
		�
		� 
			�0
			6�1
		�
	�
	5�0			5 is the flag for space or tabs found
	^�4~0	Loop while trailing spaces and tabs
		!�11~64
			�`		Space
				5�1
			�
			�I	Tab
				5�1
			�
			�J		Line feed
				�0
				|�Clear line if it has spaces or tabs
					�~51
						
					�
				�
			�
			��	Real line - leave it alone
				�0
				6�1
			�
		�
	�
	�Indent_get
	-				Install the copied chars.
	0
	|�
		�~61		True text line
		�
		�1~3=0		Intervening blank lines
			<comcol
			�1

			<	
			14~8-
			< 
			15~8-
		�
	�
	<comcol
	3=
				Set comcol
	�
	� 
		
	�
�


unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.