keyboard.rc
author Claus Gittinger <cg@exept.de>
Sun, 19 Jan 2020 16:28:21 +0100
changeset 1620 6437a27b72fc
parent 1615 8c1a90abfb5a
child 1623 10c3c63bebd2
permissions -rw-r--r--
*** empty log message ***

"*
 * Encoding: iso8859-1
 *
 * $Header$
 *
 * MIMEType: application/x-smalltalk-source
 *
 * ST/X startup configuration file:
 *
 * sample keyboard.rc - file
 *
 * this file defines some 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. After a change, file it in the running st/x,
 * using the fileBrowser's fileIn function.
 *
 * These are my personal preferrences which may not be
 * correct for your environment.
 *
 * WARNING:
 *   please keep the expressions below free from manipulating
 *   global state - all that should be done here is to set up the current
 *   screen's keyboard map.
 * Reason: in multihead applications, this will be consulted for each
 * new display screen.
 *
 * Notice:
 *   on some systems, some key-combinations are already taken/reserved
 *   by the window manager or operating system. In particular, this applies
 *   to the MaxOSX version, where many CMD-key combinations are already
 *   eaten by XQuartz or the system. Therefore, you'll find duplicate
 *   associations where both CTRL-x and CMD-x (and sometimes even ALT-x)
 *   are assigned to the same logical keyboard function.
 *
 * Also Notice:
 *   keyboard macros are little code-snippets to be executed whenever a
 *   macro key is pressed. This is done in a two step translation process:
 *   first the physical key is xlated to a logical key (in the map below),
 *   then a corresponding macro association is looked up.
 *   Macros are defined in a separate file named 'keyboardMacros.rc'.
 *"
!
Smalltalk fileIn:'keyboardMacros.rc'.
!

"*
 * 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 screen|

screen := Screen current.
map := screen keyboardMap.

#(
    #Cmd     #Alt
    #Cmd     #Menu
"/    #Cmd     #Mode_switch
    #Menu    #Appl
    #Menu    #CtrlAppl
    #Menu    #CmdAppl

"/     #'Hardcopy'     #'Super_R'
    #'Alt'     #'Super_L'
    #'Alt'     #'Hyper_R'

    #UserInterrupt    #Break      "WIN"
    #UserAbort        #CtrlCancel "WIN: abort window process, but no debugger"
    #UserAbort        #CtrlPause
    #UserAbort        #CtrlBreak  "X11: abort window process, but no debugger"
    #UserAbort        #CmdY
    #FlushInput       #CtrlX     "flush typeahead input"
    #DestroyView      #CmdCtrlX  "to destroy dead views"
    #DestroyTopView   #CmdCtrlx  "to destroy dead views"

    #CloseWindowRequest      #CmdF4

    #DoIt          #Cmdd          "i e  Cmd-d / Alt-d (sometimes Meta-d)"
    #DoIt          #Ctrld
    #InspectIt     #Cmdi          "evaluate & inspect result"
    #InspectIt     #Ctrlq
    #PrintIt       #Cmdp          "evaluate and paste result"
    #PrintIt       #Ctrlp
    #ReplaceIt     #CmdP          "evaluate and replace selection by result"
    #BrowseIt      #CmdB
    #BrowseIt      #CtrlB
    #ImplementorsOfIt      #CtrlI
    #ImplementorsOfIt      #CmdI
    "/     #SendersOfIt      #CtrlS
    "/     #SendersOfIt      #CmdS

    #ToggleInsertMode  #AltInsert
    #Copy          #CtrlInsert
    #Paste         #ShiftInsert

    #Copy          #Cmdc          "copy selection to buffer"
    #Copy          #Ctrlc         "copy selection to buffer"

    #Cut           #Cmdx          "cut selection into buffer"
    #Cut           #Ctrlx
    #Paste         #Cmdv          "paste buffer or external selection"
    #Paste         #Ctrlv
    #PasteFromHistory         #CmdV          "show paste history"
    #PasteFromHistory         #CtrlV         "show paste history"
    #Replace       #Cmdr
    #Replace       #Ctrlr
    #Join          #Ctrlj         "join lines"
    #Join          #Cmdj          "join lines"
    #Find          #Cmds          "open searchbox"
    #Find          #Ctrlf
    #FindNext      #Cmdf          "search fwd for last searchpattern or selection"
    #FindPrev      #Cmdb          "search bwd for last searchpattern or selection"
    #FindPrev      #Ctrlb
    #FindNext      #Altf          "search fwd for last searchpattern or selection"
    #FindPrev      #Altb          "search bwd for last searchpattern or selection"
    #SelectAll     #CmdA          "that is Alt-shift-a"
    #SelectAll     #Ctrla
    #GotoLine      #Ctrll
    #GotoLine      #Ctrlg
    #SelectWord    #Cmdw          "select word under cursor"
    #Undo          #Ctrlz
    #Redo          #Ctrly

    #Accept        #Cmda
    #Accept        #Ctrls

    #Explain       #Cmde
    #Explain       #Cmdh
    #Format        #CmdF              "that is Alt-shift-F"
"/     #Format        #CtrlF         "that is Ctrl-shift-F"

"/     #DeleteLine    #CtrlX

    #NextPage        #Next     "typically labelled PageDown on keyboard"
    #PreviousPage    #Prior    "typically labelled PageUp on keyboard"

"/     #PreviousPage    #Ctrlb    "vi behavior"
"/     #NextPage        #Ctrlf    "vi behavior"
"/     #HalfPageUp      #Ctrlu
"/     #HalfPageDown    #Ctrld

"/ old setting:
"/     #BeginOfText     #Home     "some prefer to bind #BeginOfLine to #Home"
"/     #EndOfText       #End      "some prefer to bind #EndOfLine to #End"
"/
"/ new setting:
    #BeginOfLine     #Home
    #EndOfLine       #End
    #BeginOfText     #CtrlHome
    #EndOfText       #CtrlEnd

    #SelectFromBeginning #ShiftHome
    #SelectToEnd         #ShiftEnd

    #EndOfLine       #Ctrle
    #NextWord        #Ctrlw
    #EndOfWord       #CtrlW

    #NextWord        #CtrlCursorRight
    #PreviousWord    #CtrlCursorLeft

    #OpenWorkspaceOnIt Ctrlo

    #ScrollUp        #CtrlCursorUp
    #ScrollUp        #CmdCursorUp
    #ScrollDown      #CtrlCursorDown
    #ScrollDown      #CmdCursorDown

    #SearchMatchingParent     #Ctrlm
    #SelectMatchingParents    #Cmdm

    #SelectToEnd              #CtrlE    "that is ctrl-shift-e"
    #SelectFromBeginning      #CtrlA    "that is ctrl-shift-a"
    #ExpandSelectionByLine    #Cmdl     "try multiple Cmd-l's ..."
    #ExpandSelectionByWord    #CmdW     "try multiple Cmd-w's ..."
"/    #ExpandSelectionByWord    #CtrlW    "that is ctrl-shift-w"

    #ZoomIn     #'Cmd+'
    #ZoomOut    #'Cmd-'
    #ZoomInAll  #'Cmd*'
    #ZoomOutAll #'Cmd_'

    #ZoomIn     #'Ctrl+'
    #ZoomOut    #'Ctrl-'
    #ZoomInAll  #'Ctrl*'
    #ZoomOutAll #'Ctrlunderscore'
    #ZoomOutAll #'Ctrl_'

    "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)
    "

    #FocusNext        #CmdCursorRight    "experimental"
    #FocusPrevious    #CmdCursorLeft     "experimental"
    #FocusNext        #CmdCursorDown     "experimental"
    #FocusPrevious    #CmdCursorUp       "experimental"

    #FocusNext        #AltCursorRight    "experimental"
    #FocusPrevious    #AltCursorLeft     "experimental"
    #FocusNext        #AltCursorDown     "experimental"
    #FocusPrevious    #AltCursorUp       "experimental"
"/     #FocusNext        #CtrlCursorRight   "experimental"
"/     #FocusPrevious    #CtrlCursorLeft    "experimental"


    #NonInsertingTab     #ShiftTab
    #BackTab             #CtrlTab
    #NonInsertingTab     #'ISO_Left_Tab'
"/     #ToggleTabs          #CtrlTab

    #FocusNext        #AltTab            "experimental"
    #FocusNext        #CmdTab            "experimental"
    #FocusPrevious    #'CmdISO_Left_Tab'
"/ map bindValue:#Tab              #'ISO_Left_Tab'
    #Menu             #Cmdz
) pairWiseDo:[:symbolic :key |
    map bindValue:symbolic to:key.
].

OperatingSystem isMSWINDOWSlike ifTrue:[
    map bindValue:#UserAbort        to:#Pause.
] ifFalse:[
    map bindValue:#UserInterrupt    to:#Pause. "X11"
].

OperatingSystem isOSXlike ifTrue:[
    "/ Screen current keyboardMap bindValue:#ToggleInsertMode to:#CtrlO
    map bindValue:#ToggleInsertMode        to:#CtrlO.
].

"*
 * ISO LATIN 1 symbolic characters - map to iso8859-1/unicode 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              16rC6
	ae              16rE6
	ssharp          16rDF
	oe              16r153
	OE              16r152

	"/ 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
	acute           16rEF
	division        16rF7
	thorn           16rFE
	infinity        16r221E
	"/ ellipsis        16r2026 -- very disturbing
	endash          16r2013
	dagger          16r2020
	approxeq        16r2248
	radical         16r221A

	guillemotleft   16rAB
	guillemotright  16rBF

	enfilledcircbullet  16r2022

	section         16rA7
	rightdoublequotemark 16rAB
	leftdoublequotemark  16rBB
	notsign         16rAC
	degree          16rB0
	twosuperior     16rB2
	threesuperior   16rB3
	mu              16rB5
	cedilla         16rB8
	onesuperior     16rB9
	onequarter      16rBC
	onehalf         16rBD
	threequarter    16rBE

	copyright       16rA9
	registered      16rAE

	Greek_pi        16r03c0
	Greek_Pi        16r220F
	Greek_OMEGA     16r03a9

	EuroSign        16r20AC
	yen             16rA5
) 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:#Return to:#'KP_Enter'.
map bindValue:#Delete 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:#'Control_L'.       "/ 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.
map bindValue:#DeleteWordBeforeCursor    to:#CtrlBackSpace.
map bindValue:#Delete                    to:#CmdBackSpace.

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

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

map bindValue:#SaveAs        to:#CtrlS.
map bindValue:#SaveAs        to:#CmdS.

"/ xxxF5      -> macro ReplaceSelectionByUnixCommandsOutput (unix command output paste)
"/ CtrlTab -> macro ToggleTabs (toggle 4/8 tabs)
"/ F10     -> macro IndentBy4 (indent by 4)
"/ F9      -> macro UndentBy4 (undent by 4)
"/ F12     -> macro IndentBy1 (indent by 1)
"/ F11     -> macro UndentBy1 (undent by 1)
"/ F2      -> rename
"/ F4      -> commentSelection
"/ F5      -> uncommentSelection

"/ map bindValue:#ReplaceSelectionByUnixCommandsOutput  to:#F5.
"/ map bindValue:#CmdF97 to:#F7.
"/ map bindValue:#CmdF96 to:#F6.

map bindValue:#IndentBy4 to:#F10.
map bindValue:#UndentBy4 to:#F9.

map bindValue:#IndentBy1 to:#F12.
map bindValue:#UndentBy1 to:#F11.

map bindValue:#ConvertSelectionToLowercaseOrUppercaseOrUppercaseFirst to:#F6.
map bindValue:#ConvertSelectionToUppercase to:#CtrlF6.

map bindValue:#Rename           to:#F2.
map bindValue:#FindAgain        to:#F3.   "/ search again in same direction
map bindValue:#CommentSelection to:#F4.
map bindValue:#UncommentSelection to:#F5.

map bindValue:#ParenthizeSelection to:#'Cmd('.
map bindValue:#UnparenthizeSelection to:#'Cmd)'.

map bindValue:#LearnKeyboardMacro   to:#CtrlF2.
map bindValue:#ExecuteKeyboardMacro to:#CmdF2.
map bindValue:#ExecuteKeyboardMacro to:#CtrlF3.
map bindValue:#LearnKeyboardMacro   to:#CmdL.
map bindValue:#ExecuteKeyboardMacro to:#CmdM.

map bindValue:#CodeCompletion     to:#'Ctrl '.          "that is Ctrl-Space"
map bindValue:#CodeCompletion     to:#'Ctrlspace'.      "mhmh - why is this sent on linux, and the above on windows (must check) ?"

map bindValue:#ExpandAbbreviation to:#'Cmd '.     "that is Alt-Space"
map bindValue:#ExpandAbbreviation to:#nobreakspace.

"/ map bindValue:#PasteBlockEvaluationsOutput to:#CmdV.

"/
"/ 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 server's 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.)
"/
OperatingSystem isOSXlike ifFalse:[
    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@'.
    map bindValue:$# to:#'Cmd#'.
].

OperatingSystem isOSXlike ifTrue:[
    map bindValue:#Delete to:#'AltBackSpace'.
    "/ there seems to be a bug in the english xmap (sigh)
    map bindValue:$' to:#'dead_acute'.
].

map bindValue:#UserInterrupt to:#'Cmd.' .     "/ for squeak compatibility
map bindValue:#UserInterrupt to:#'Ctrl.' .    "/ for vw compatibility

!