keyboard.rc
author Claus Gittinger <cg@exept.de>
Tue, 06 Jul 1999 17:16:07 +0200
changeset 368 e998b6392d10
parent 356 4275f251cb37
child 370 9aeb341c2dac
permissions -rw-r--r--
*** empty log message ***

"*
 * $Header$
 *
 * ST/X startup configuration file:
 *
 * sample keyboard.rc - file
 *
 * this file defines some keyboard macros and adds mappings for
 * common function keys. These definitions used to be in 'private.rc',
 * but have been extracted into this separate file to allow easier
 * sharing of rc files (users having different private files, but want
 * to use the same keyboard mappings / keyboard macros)
 *
 * a copy of this file can reside in $home/.smalltalk/keyboard.rc or
 * in the current directory.
 *
 * these are my personal preferrences which may not be
 * correct for your environment
 *"

|macros|

"/
"/ define some keyboard macros as virtual function-keys:
"/ Cmd-F99: paste the output of a selected unix command ..
"/ Cmd-F98: toggle between 4 and 8 col tab setting
"/ Cmd-F96: pipe text through spelling checker and collect its output
"/ Cmd-F97: get next entry from spell-list, search and highlight it
"/ Cmd-F95: indents selection by 4
"/ Cmd-F94: undents selection by 4
"/

macros := Smalltalk at:#FunctionKeySequences.
macros isNil ifTrue:[
    macros := IdentityDictionary new.
    Smalltalk at:#FunctionKeySequences put:macros.
].

"/
"/ macro to replace a text selection by unix commands output
"/

macros at:#F99 put:'
	"replace selection by 
	 corresponding
	 unix commands output"

	|sel|

	sel := self selection.
	sel notNil ifTrue:[
	    self replace:
		(PipeStream readingFrom:(sel asString))
		    contents asString
	]'.

"/
"/ macro to toggle tabs
"/
macros at:#F98 put:'
	"toggle between 4-col 
	 and 8-col tabs"

	(tabPositions == self class tab4Positions)
	     ifTrue:[self setTab8]
	     ifFalse:[self setTab4]'.

"/
"/ macro to get next spelling error, and select it
"/
macros at:#F97 put:'
	|errs thisErr sl sc|

	thisErr := Smalltalk at:#''_thisError''.
	thisErr isNil ifTrue:[
	    errs := Smalltalk at:#''_spellOutput''.
	    (errs notNil and:[errs notEmpty]) ifTrue:[
		thisErr := errs removeFirst.
		errs isEmpty ifTrue:[Smalltalk removeKey:''_spellOut'']
	    ].
	    Smalltalk at:#''_lastErrLine'' put:1.
	    Smalltalk at:#''_lastErrCol'' put:1.
	].
	thisErr notNil ifTrue:[
	    sl := Smalltalk at:#''_lastErrLine''.
	    sc := Smalltalk at:#''_lastErrCol''.
	    self searchForwardFor:thisErr
		 startingAtLine:sl col:sc 
		 ifFound:[:fl :fc | self selectWordAtLine:fl col:fc.
				    Smalltalk at:#''_lastErrLine'' put:fl.
				    Smalltalk at:#''_lastErrCol'' put:fc+1]
		 ifAbsent:[self device beep]
	]'.

"/
"/ macro to send contents to spell; remember spelling errors
"/ does not work on all systems (some do not have spell ...)
"/
macros at:#F96 put:'
	|p f s|

	f := Filename newTemporary. s := f writeStream.
	s nextPutAll:self contents asString.
	s close.
	p := PipeStream readingFrom:''spell '' , f pathName.
	Smalltalk at:#''_spellOutput'' put:p contents asString asCollectionOfLines.
	p close.
	self information:''F7 positions on the next spelling error''.
	'.

"/
"/ macro to indent by 4
"/
macros at:#F95 put:'
	"indent selected line-range 
	 by 4 spaces (i.e. to the right)"

	self selectionStartLine notNil ifTrue:[    
	    self selectionStartLine to:self selectionEndLine-1 do:[:lineNr |
		|line|

		line := self listAt:lineNr.
		line notNil ifTrue:[
		    line notEmpty ifTrue:[
			line := ''    '' , line.
			self withoutRedrawAt:lineNr put:line.
			self invalidateLine:lineNr.
		    ]
		]
	    ].
	]
	'.

"/
"/ macro to undent by 4
"/
macros at:#F94 put:'
	"undent selected line-range 
	 by 4 spaces (i.e. to the left)"

	self selectionStartLine notNil ifTrue:[    
	    self selectionStartLine to:self selectionEndLine-1 do:[:lineNr |
		|line|

		line := self listAt:lineNr.
		line notNil ifTrue:[
		    line notEmpty ifTrue:[
			(line startsWith:''    '') ifTrue:[
			    line := line copyFrom:5.
			    self withoutRedrawAt:lineNr put:line.
			    self invalidateLine:lineNr.
			]
		    ]
		]
	    ].
	]
	'.
"/
"/ macro to indent by 1
"/
macros at:#F93 put:'
	"indent selected line-range 
	 by 1 space (i.e. to the right)"

	self selectionStartLine notNil ifTrue:[    
	    self selectionStartLine to:self selectionEndLine-1 do:[:lineNr |
		|line|

		line := self listAt:lineNr.
		line notNil ifTrue:[
		    line notEmpty ifTrue:[
			line := '' '' , line.
			self withoutRedrawAt:lineNr put:line.
			self invalidateLine:lineNr.
		    ]
		]
	    ].
	]
	'.

"/
"/ macro to undent by 1
"/
macros at:#F92 put:'
	"undent selected line-range 
	 by 1 space (i.e. to the left)"

	self selectionStartLine notNil ifTrue:[    
	    self selectionStartLine to:self selectionEndLine-1 do:[:lineNr |
		|line|

		line := self listAt:lineNr.
		line notNil ifTrue:[
		    line notEmpty ifTrue:[
			(line startsWith:'' '') ifTrue:[
			    line := line copyFrom:2.
			    self withoutRedrawAt:lineNr put:line.
			    self invalidateLine:lineNr.
			]
		    ]
		]
	    ].
	]
	'.
!

"*
 * key bindings common to all display types
 * use event monitor, to see what the Xserver sends us;
 * put display-specific stuff into a d_hostName.rc file.
 *"
|map|

map := Display keyboardMap.

(Display serverVendor startsWith:'DECWINDOWS') ifTrue:[
    "/ DEC has messed up the ESC key completely.
    "/ map ALT-` onto ESC for our convenience.
    "/
    "/ also, the right compose key (comes in as 'AltMulti_key' or
    "/ 'CtrlMulti_key' depending on the keyboard) is mapped
    "/ to 'Compose'.
    map bindValue:#Escape  to:#'Cmd`'.
    map bindValue:#Compose to:#'AltMulti_key'.    "/ the right compose key

    map bindValue:#Return  to:#'KP_Enter'.        "/ the keypads return key
].  

map bindValue:#'Alt'  to:#'Super_L'.  
map bindValue:#'Alt'  to:#'Hyper_R'.  

map bindValue:#UserInterrupt  to:#Ctrlc.    "interrupt window process"
map bindValue:#UserAbort      to:#Ctrly.    "abort window process, but no debugger"
map bindValue:#FlushInput     to:#CtrlX.    "flush typeahead input"
map bindValue:#DestroyView    to:#CmdCtrlX. "to destroy dead views"
map bindValue:#DestroyTopView to:#CmdCtrlx. "to destroy dead views"

map bindValue:#DoIt       to:#Cmdd.         "i.e. Cmd-d / Alt-d (sometimes Meta-d)"
map bindValue:#InspectIt  to:#Cmdi.         "evaluate & inspect result"
map bindValue:#PrintIt    to:#Cmdp.         "evaluate and paste result"

map bindValue:#Copy       to:#Cmdc.         "copy selection to buffer"
map bindValue:#Cut        to:#Cmdx.         "cut selection into buffer"
map bindValue:#Paste      to:#Cmdv.         "paste buffer or external selection"
map bindValue:#Replace    to:#Cmdr.         "same as paste"
map bindValue:#Find       to:#Cmds.         "open searchbox"
map bindValue:#FindNext   to:#Cmdf.         "search fwd for last searchpattern or selection"
map bindValue:#FindPrev   to:#Cmdb.         "search bwd for last searchpattern or selection"
map bindValue:#SelectAll  to:#CmdA.         "that is Alt-shift-a"
map bindValue:#GotoLine   to:#Cmdg.
map bindValue:#SelectWord to:#Cmdw.         "select word under cursor"

map bindValue:#Accept     to:#Cmda.
map bindValue:#Explain    to:#Cmde.
map bindValue:#Explain    to:#Cmdh.

map bindValue:#DeleteLine to:#Ctrlx.

map bindValue:#NextPage     to:#Next.    "typically labelled PageDown on keyboard"
map bindValue:#PreviousPage to:#Prior.   "typically labelled PageUp on keyboard"

map bindValue:#PreviousPage to:#Ctrlb.   "vi behavior"
map bindValue:#NextPage     to:#Ctrlf.   "vi behavior"
map bindValue:#HalfPageUp   to:#Ctrlu.
map bindValue:#HalfPageDown to:#Ctrld.

map bindValue:#BeginOfText  to:#Home.    "some prefer to bind #BeginOfLine to #Home"
map bindValue:#EndOfText    to:#End.     "some prefer to bind #EndOfLine to #End"
map bindValue:#BeginOfLine  to:#Ctrla.
map bindValue:#EndOfLine    to:#Ctrle.
map bindValue:#NextWord     to:#Ctrlw.
map bindValue:#NextWord     to:#CtrlCursorRight.  
map bindValue:#PreviousWord to:#CtrlCursorLeft.  

map bindValue:#ScrollUp     to:#CtrlCursorUp.    
map bindValue:#ScrollDown   to:#CtrlCursorDown.    

map bindValue:#SearchMatchingParent  to:#Ctrlm.
map bindValue:#SelectMatchingParents to:#Cmdm.

map bindValue:#SelectToEnd           to:#CtrlE.   "that is ctrl-shift-e"
map bindValue:#SelectFromBeginning   to:#CtrlA.   "that is ctrl-shift-a"
map bindValue:#ExpandSelectionByLine to:#Ctrll.   "try multiple Ctrl-l's ..."

"Notice:
  Cmd-CursorLeft/Right and Alt-CursorLeft/Right
  are also used by some winmdowmanagers (fvwm)
  if this is the case on your system, either
  change the following to use different keys,
  or change the windowmanagers configuration file
  (usr/lib/X11/xxxwm/*rc).
  The above is the reason that the following defines Ctrl-xxx
  as an alternative (mwm in the INDY also uses the alt-sequences)
"
map bindValue:#FocusNext     to:#CmdCursorRight.   "experimental"
map bindValue:#FocusPrevious to:#CmdCursorLeft.    "experimental"
map bindValue:#FocusNext     to:#AltCursorRight.   "experimental"
map bindValue:#FocusPrevious to:#AltCursorLeft.    "experimental"
map bindValue:#FocusNext     to:#AltCursorDown.    "experimental"
map bindValue:#FocusPrevious to:#AltCursorUp.      "experimental"
"/ map bindValue:#FocusNext     to:#CtrlCursorRight.  "experimental"
"/ map bindValue:#FocusPrevious to:#CtrlCursorLeft.   "experimental"

map bindValue:#FocusNext     to:#CtrlTab.          "experimental"
map bindValue:#FocusNext     to:#CmdTab.           "experimental"

map bindValue:#Menu          to:#Cmdz.             

"*
 * ISO LATIN 1 symbolic characters - map to iso8859 values
 * not all Xservers send those correctly.
 * As a fall back, dieresis mappings using Alt-key sequences are found at
 * the end.
 *"

#(
	"/ dieresis characters

	Udiaeresis      16rDC
	Adiaeresis      16rC4
	Odiaeresis      16rD6
	udiaeresis      16rFC
	adiaeresis      16rE4
	odiaeresis      16rF6
	ydiaeresis      16rFF

	"/ grave

	Agrave          16rC0
	Egrave          16rC8
	Igrave          16rCC
	Ograve          16rCC
	Ugrave          16rD9
	agrave          16rE0
	egrave          16rE8
	igrave          16rEC
	ograve          16rF2
	ugrave          16rF9

	"/ acute

	Aacute          16rC1
	Eacute          16rC9
	Iacute          16rCD
	Oacute          16rD3
	Uacute          16rDA
	Yacute          16rDD
	aacute          16rE1
	eacute          16rE9
	iacute          16rED
	oacute          16rF3
	uacute          16rFA
	yacute          16rFD

	"/ circumflex

	Acircumflex     16rC2
	Ecircumflex     16rCA 
	Icircumflex     16rCE 
	Ocircumflex     16rD4 
	Ucircumflex     16rDB 
	acircumflex     16rE2 
	ecircumflex     16rEA 
	icircumflex     16rEE 
	ocircumflex     16rF4 
	ucircumflex     16rFB 

	"/ tilde

	Atilde          16rC3 
	Ntilde          16rD1 
	atilde          16rE3 
	ntilde          16rF1 

	"/ ring

	Aring           16rC4 
	aring           16rE4 

	"/ ligatures

	AE              16rC5 
	ae              16rE5 
	ssharp          16rDF

	"/ cedilla

	Ccedilla        16rC7 
	ccedilla        16rE7 

	"/ slashed

	Ooblique        16rD8 
	oslash          16rF8 

	"/ misc (if on your keyboard)

	Eth             16rD0     "/ some old servers still use this
	ETH             16rD0 
	eth             16rF0 
	multiply        16rD7 
	Thorn           16rDE   "/ some old servers still use this
	THORN           16rDE   "/ some old servers still use this
	division        16rF7 
	thorn           16rFE 

	section         16rA7
	degree          16rB0
	twosuperior     16rB2
	threesuperior   16rB3
	mu              16rB5
) pairWiseDo:[:symbolic :numeric |
	map bindValue:(Character value:numeric) to:symbolic.
].

"*
 * need more here (katakana, arabic, cyrillic, greek etc.)
 *"

"*
 * numeric keypad - binding to normal numeric keys
 *"
"/ map bindValue:$0 to:#'KP_Insert'.
"/ map bindValue:$1 to:#'KP_End'.
"/ map bindValue:$2 to:#'KP_Down'.
"/ map bindValue:$3 to:#'KP_Next'.
"/ map bindValue:$4 to:#'KP_Left'.
"/ map bindValue:$5 to:#'KP_Begin'.
"/ map bindValue:$6 to:#'KP_Right'.
"/ map bindValue:$7 to:#'KP_Home'.
"/ map bindValue:$8 to:#'KP_Up'.
"/ map bindValue:$9 to:#'KP_Prior'.
"/ map bindValue:#Retrun to:#'KP_Enter'.
"/ map bindValue:#Backspace to:#'KP_Delete'.


"/ remove these lines, if your keyboard has a COMPOSE-key.
"/ None of our Xdisplays here has one - so we simulate it using CTRL-R ...
"/ which on some (of our) servers comes pretranslated as Multi_key, 
"/ CtrlMulti_key or even Mode_switch.

map bindValue:#Compose     to:#'Control_R'.       "/ the right compose key
map bindValue:#Compose     to:#'Multi_key'.       "/ the right compose key
map bindValue:#Compose     to:#'CtrlMulti_key'.   "/ the right compose key
"/ map bindValue:#Compose     to:#'Mode_switch'.     


"/ a kludge: some Xservers send #Delete for both the backspace
"/ and the Delete key. In this case, we use the Backspace function
"/ for both keys. If your Xserver does not do this (it should not)
"/ remove or comment the following 'bindValue:#BackSpace'-line:
"/

"/ map bindValue:#BackSpace     to:#Delete.

"/
"/ my personal preferences - comment it, if you do not like them
"/ bind function and other keys as:
"/
"/ F1            - again
"/ F3            - comment-it
"/ F4            - uncomment-it
"/ F5            - paste shell output
"/ F9            - undent by 4
"/ F10           - indent by 4
"/ Control-R     - Compose key
"/ Break         - UserInterrupt

"/
"/ convenient functions on the keyboard
"/
map bindValue:#Again         to:#F1.
map bindValue:#UserInterrupt to:#Break.
"/ map bindValue:#PrintIt       to:#Print.      "/ called PrintScreen on most keyboards
"/ map bindValue:#InspectIt     to:#Execute.    "/ called SysReq on most keyboards

map bindValue:#SaveAs        to:#CmdS.

"/ F5      -> macroF99 (unix command output paste)
"/ CtrlTab -> macroF98 (toggle 4/8 tabs)
"/ F10     -> macroF95 (indent by 4)
"/ F9      -> macroF94 (undent by 4)
"/ F12     -> macroF93 (indent by 1)
"/ F11     -> macroF92 (undent by 1)
"/ F3      -> commentSelection
"/ F4      -> uncommentSelection

map bindValue:#CmdF99  to:#F5.
map bindValue:#CmdF98 to:#CtrlTab.
"/ map bindValue:#CmdF97 to:#F7.
"/ map bindValue:#CmdF96 to:#F6.
map bindValue:#CmdF95 to:#F10.
map bindValue:#CmdF94 to:#F9.

map bindValue:#CmdF93 to:#F12.
map bindValue:#CmdF92 to:#F11.

map bindValue:#CommentSelection to:#F3.
map bindValue:#UncommentSelection to:#F4.

"/
"/ since some of my machines have german keyboards ;-)
"/ and I like to be able to edit my files on all machines,
"/ I need a translation in both ways.
"/ you'd normally not define things in both directions.
"/
"/ actually, these things belong into the servers modmap or 
"/ into a display specific d_<displayName>.rc ...
"/
"/ german national characters on a US keyboard:
"/ comment this, if you have a german keyboard.
"/
"/map bindValue:(Character value:16rFC) to:#'Cmd['.   "/ u dieresis
"/map bindValue:(Character value:16rE4) to:#'Cmd'''.  "/ a dieresis
"/map bindValue:(Character value:16rF6) to:#'Cmd;'.   "/ o dieresis
"/map bindValue:(Character value:16rDC) to:#'Cmd{'.   "/ U dieresis
"/map bindValue:(Character value:16rC4) to:#'Cmd"'.   "/ A dieresis
"/map bindValue:(Character value:16rD6) to:#'Cmd:'.   "/ O dieresis
"/map bindValue:(Character value:16rDF) to:#'Cmd-'.   "/ s-sharp

"/
"/ US characters on national keyboards:
"/ (on many national keyboards, the x-server does NOT correctly
"/  xlate characters .... on others, it does and you may remove/comment
"/  the following.)
"/
map bindValue:$[ to:#'Alt['.
map bindValue:$] to:#'Alt]'.
map bindValue:$| to:#'Alt|'.
map bindValue:${ to:#'Alt{'.
map bindValue:$} to:#'Alt}'.
map bindValue:$\ to:#'Alt\'.
map bindValue:$~ to:#'Alt~'.
map bindValue:$@ to:#'Alt@'.

map bindValue:$[ to:#'Cmd['.      
map bindValue:$] to:#'Cmd]'.
map bindValue:$| to:#'Cmd|'.
map bindValue:${ to:#'Cmd{'.
map bindValue:$} to:#'Cmd}'.
map bindValue:$\ to:#'Cmd\'.
map bindValue:$~ to:#'Cmd~'.
map bindValue:$@ to:#'Cmd@'.


!