├── Readme.org ├── commands.ahk ├── commands_util.ahk ├── ewow.ahk ├── fundamental.ahk ├── init.ahk ├── keybinds.ahk └── prefix.ahk /Readme.org: -------------------------------------------------------------------------------- 1 | * EWOW -- Emacs Way of Operating Windows 2 | ** Features 3 | 4 | + allows Emacs-like commands and keybinds (almost) everywhere in 5 | Windows 6 | 7 | - keyboard macros 8 | 9 | - prefix digit-argument 10 | - ex. C-3 C-n -> go 3 lines down 11 | 12 | - Emacs-style region selection (i.e. set-mark-command) 13 | 14 | - ... etc 15 | 16 | ** Usage 17 | 18 | Install AutoHotKey_L, and run "ewow.ahk" then emacs commands are 19 | available. You can quit EWOW from tasktray icon. 20 | 21 | ** Configuration 22 | *** Abstract 23 | 24 | EWOW is a set of AutoHotKey scripts : 25 | 26 | - fundamental.ahk :: provides a bunch of functions and variables, that 27 | are used to implement emacs-like commands and keybinds 28 | 29 | - commands.ahk :: provides basic emacs commands implementation 30 | 31 | - init.ahk :: *PUT YOUR SETTINGS HERE*. 32 | 33 | - keybinds.ahk :: provides the default keybinds 34 | 35 | "ewow.ahk" just loads them in sequence. You can configure EWOW by 36 | writing AHK script in "init.ahk", so that "ewow.ahk" will load it. 37 | Some recomended configurations are provided and commented-out in 38 | "init.ahk", and you can uncomment to try them. 39 | 40 | *** How To Write AHK Script ? 41 | 42 | An AHK script basically consists of two parts : 43 | 44 | - auto-exec section 45 | - hotkey definitions 46 | 47 | they must be in the order. That is, you CANNOT write auto-exec section 48 | after hotkey definitions. 49 | 50 | **** auto-exec section 51 | 52 | In auto-exec section, you can define define/call functions and set 53 | variables, like usual programming languages. Calling functions and 54 | setting variables are as easy as : 55 | 56 | : foo() ; function call 57 | : bar = baz ; set variable value 58 | 59 | If you need to define functions to configure EWOW, please read AHK 60 | manuals. 61 | 62 | You may also import other EWOW packages in auto-execution section : 63 | 64 | : #Include evil.ahk 65 | 66 | **** hotkey definitions 67 | 68 | Hotkey definitions are similar to keybinds in emacs. To rebind =C-f= 69 | key to =forward_char= command, you just need to add following to your 70 | "init.ahk". 71 | 72 | : ^f:: forward_char() 73 | 74 | The letter =^= here indicates that =f= is modified by =Ctrl= 75 | key. Respectively =+= indicates =Shift= and =!= indicates 76 | =Alt=. Default Keybinds are defined in "keybinds.ahk". 77 | 78 | You may also define conditional keybinds with =#If= directive : 79 | 80 | : #If !ignored_frame() && !cx 81 | : ^f:: forward_char() 82 | : #If !ignored_frame() && cx 83 | : ^f:: find_file() 84 | 85 | The example above binds =C-f= to =forward_char= command, when =C-x= is 86 | not prefixed and the cursor is not in =ignored_frames= which is 87 | described later. If we are not in =ignored_frames= but =C-x= is 88 | prefixed, then =C-f= is bind to =find_file= command instead. Otherwise 89 | (when we are in "ignored_frames"), =C-f= is not bound. That is, 90 | =Ctrl-f= is sent to Windows normally. 91 | 92 | *** Functions and Variables provided in fundamental.ahk 93 | 94 | Following functions and variables are provided in 95 | "fundamental.ahk". You may call or set them in "init.ahk" to do some 96 | configurations. 97 | 98 | - configurable variables 99 | 100 | + ignored_frames :: a list of window-classes in which EWOW should be 101 | disabled. for example, we usually do not want 102 | get EWOW enabled in Emacs window. 103 | 104 | - read-only variables 105 | 106 | + cx :: true when =C-x= is prefixed. 107 | + mark :: true when the mark is active. 108 | 109 | - functions 110 | 111 | + ignored_frame() :: return if we are in =ignored_frames= 112 | 113 | ** Writing Extensions 114 | 115 | If you are familiar with AHK, it is easy to write your own commands or 116 | packages. Because commands are just AHK functions, and a package is 117 | basically a set of commands and variables. 118 | 119 | Though, there are some differences to be cared. PLEASE READ 120 | description below, before start writing your own extensions. 121 | 122 | *** Functions and Variables Provided for Developers 123 | 124 | - functions 125 | 126 | + send(str) :: a wrapper function of =Send= operation. PLEASE DO USE 127 | THIS instead of normal =Send= operation, so that sent 128 | keys are recorded in keyboard macros. 129 | 130 | + add_hook(var, func) :: like =add-hook= in Emacs. available hooks 131 | are described later. =var= must be a name of hook variable, and 132 | =func= must be a name of a 0-ary function. 133 | 134 | + remove_hook(var, func) :: inverse of =add_hook=. 135 | 136 | + run_hooks(var) :: run hooks added to the hook variable =var=. 137 | 138 | + alloc_tt() :: allocate an UID for =tooltip= and return it. when 139 | you use =tooltip= operation, PLEASE DO USE the ID 140 | provided by this function as =WhichToolTip= 141 | argument. there is no =free_tt()= function, so 142 | PLEASE DO REUSE the provided ID. 143 | 144 | + read_char() :: steal a key event from keyboard and return it, 145 | without sending it to Windows nor invoking 146 | commands. 147 | 148 | + set_mark() :: activate mark. 149 | 150 | + reset_mark() :: deactivate mark. 151 | 152 | - read-only variables 153 | 154 | + last_command :: the last key sequence sent to Windows. 155 | 156 | + arg :: prefixed digit argument is stored as an integer. 157 | 158 | - hooks 159 | 160 | + pre_command_hook :: hook which MUST BE CALLED manually at the 161 | beginning of command. 162 | 163 | + post_command_hook :: hook which MUST BE CALLED manually at the end 164 | of command. 165 | 166 | + after_change_hook :: hook which MUST BE CALLED manually just after 167 | changes. 168 | 169 | + before_send_hook :: hook which automatically runs before sending 170 | keys to Windows. you may assume that the variable 171 | =last_command= is set to the key sequence being sent, in the 172 | hook. 173 | 174 | + after_send_hook :: hook which automatically runs after sending 175 | keys to Windows. 176 | 177 | + after_display_transition_hook :: hook which automatically runs 178 | when the active window is switched. 179 | 180 | *** Things You MUST Do 181 | 182 | + use =send()= function instead of =Send=. 183 | 184 | + use =alloc_tt()= function when you use =ToolTip=. 185 | 186 | + call =pre_command_hook=, =post_command_hook= and =after_change_hook= 187 | from your commands manually. Your command may looks like : 188 | 189 | : my_command() 190 | : { 191 | : run_hooks("pre_command_hook") 192 | : do_something() 193 | : run_hooks("post_command_hook") 194 | : } 195 | 196 | + use local variables as well as you can, to save namespace. 197 | 198 | *** Thigs You CAN Do 199 | 200 | + hook some functions with =add_hook= 201 | 202 | : add_hook("pre_command_hook", "my_pkg_pre_command_function") 203 | 204 | + run some hooks with =run_hoks= 205 | 206 | + use =read_char()= function to steal a key input 207 | 208 | + read =last_command= and =arg= value 209 | 210 | ** Known Limitations, Bugs 211 | 212 | + some commands are not recorded in keyboard macro 213 | - =some commands= are -- commands that do not send keys to Windows 214 | 215 | + registers are not available for now 216 | -------------------------------------------------------------------------------- /commands.ahk: -------------------------------------------------------------------------------- 1 | ;; This script provides: command skeletons 2 | 3 | #Include commands_util.ahk 4 | 5 | kmacro_tt := alloc_tt() 6 | 7 | kill_ring_size = 100 8 | 9 | ;; --------- 10 | ;; utilities 11 | ;; --------- 12 | 13 | safe_cut() 14 | { 15 | ClipBoard = 16 | send("^x") 17 | ClipWait, 0.5 ; confirm that the ClipBoard is updated 18 | } 19 | 20 | ;; --------- 21 | ;; kill_ring 22 | ;; --------- 23 | 24 | kill_ring_pointer = 0 25 | 26 | kill_ring_push() 27 | { Global 28 | kill_ring_pointer := mod(kill_ring_pointer + 1, kill_ring_size) 29 | kill_ring%kill_ring_pointer% := ClipBoard 30 | } 31 | 32 | kill_ring_pop() 33 | { Global 34 | kill_ring_pointer := mod(kill_ring_pointer + kill_ring_size - 1, kill_ring_size) 35 | ClipBoard := kill_ring%kill_ring_pointer% 36 | } 37 | 38 | kill_ring_restore() 39 | { Global 40 | ClipBoard := kill_ring%kill_ring_pointer% 41 | } 42 | 43 | ;; -------------- 44 | ;; alttab command 45 | ;; -------------- 46 | 47 | ;; Usage: 48 | ;; 49 | ;; #If, alt_pressed 50 | ;; alt up:: alttab_end() 51 | ;; #If, 52 | ;; !tab:: alttab_next() 53 | 54 | alt_pressed = 0 55 | 56 | alttab_next() 57 | { Global 58 | alt_pressed = 1 59 | command_simple("{alt down}{tab}", 0, 1) 60 | } 61 | 62 | alttab_end() 63 | { Global 64 | alt_pressed = 0 65 | command_simple("{alt up}", 0, 0) 66 | } 67 | 68 | ;; ----------- 69 | ;; send itself 70 | ;; ----------- 71 | 72 | ;; send itself ARG times (for ASCII keys) 73 | self_insert_command() 74 | { 75 | command_simple(A_ThisHotKey, 1, 1) 76 | } 77 | 78 | ;; send itself ARG times (for non-ASCII keys) 79 | self_send_command() 80 | { 81 | tmp = {%A_ThisHotKey%} 82 | command_simple(tmp, 0, 1) 83 | } 84 | 85 | ;; send mouse event itself 86 | mouse_event_command() 87 | { 88 | MouseGetPos, x, y 89 | 90 | RegExMatch(A_ThisHotKey, "(\W*)(\w*)( up)?", res) 91 | 92 | If res2 = LButton 93 | key = L 94 | Else If res2 = RButton 95 | key = R 96 | Else If res2 = MButton 97 | key = M 98 | Else If res2 = XButton1 99 | key = X1 100 | Else If res2 = XButton2 101 | key = X2 102 | Else 103 | Return 104 | 105 | If res3 = 106 | updn = D 107 | Else 108 | updn = U 109 | 110 | key = %res1%{Click, %key%, %x%, %y%, 1, %updn%} 111 | command_simple(key, 0, 1) 112 | } 113 | 114 | ;; digit argument 115 | digit_argument() 116 | { Global 117 | Local tmp 118 | run_hooks("pre_command_hook") 119 | StringTrimLeft, tmp, A_ThisHotKey, 1 120 | set_digit_argument(arg * 10 + tmp) 121 | run_hooks("post_command_hook") 122 | } 123 | 124 | ;; ------ 125 | ;; system 126 | ;; ------ 127 | 128 | ;; do nothing 129 | ignore() 130 | { 131 | run_hooks("pre_command_hook") 132 | run_hooks("post_command_hook") 133 | } 134 | 135 | set_mark_command() 136 | { 137 | command_simple("set_mark", 0, 0) 138 | } 139 | 140 | set_cx_command() 141 | { Global 142 | run_hooks("pre_command_hook") 143 | set_digit_argument(arg) 144 | set_cx() 145 | run_hooks("post_command_hook") 146 | } 147 | 148 | ;; send ESC and reset variables 149 | keyboard_quit() 150 | { Global 151 | run_hooks("pre_command_hook") 152 | If mark 153 | reset_mark() 154 | Else 155 | send("{escape}") 156 | run_hooks("post_command_hook") 157 | } 158 | 159 | ;; repeat last command again ARG times 160 | repeat() 161 | { Global 162 | command_simple(last_command, 0, 1) 163 | } 164 | 165 | ;; ------ 166 | ;; kmacro 167 | ;; ------ 168 | 169 | ;; functions 170 | 171 | kmacro_recoding = 0 172 | kmacro_count = 0 173 | 174 | kmacro_start() 175 | { Global 176 | kmacro_recoding = 1 177 | kmacro_count = 0 178 | ToolTip, REC, , , %kmacro_tt% 179 | } 180 | 181 | kmacro_after_send_function() 182 | { Global 183 | If kmacro_recoding 184 | { 185 | kmacro_count++ 186 | kmacro%kmacro_count% := last_command 187 | ToolTip, %last_command%, , , %kmacro_tt% 188 | } 189 | } 190 | 191 | kmacro_end() 192 | { Global 193 | kmacro_recoding = 0 194 | ToolTip, , , , %kmacro_tt% 195 | } 196 | 197 | kmacro_call() 198 | { Global 199 | Local varname, x, y 200 | MouseGetPos, x, y 201 | Loop, %kmacro_count% 202 | { 203 | varname := kmacro%A_Index% 204 | Send, %varname% 205 | } 206 | Send, {Click, , %x%, %y%, 0} 207 | } 208 | 209 | add_hook("after_send_hook", "kmacro_after_send_function") 210 | 211 | ;; commands 212 | 213 | kmacro_end_macro() 214 | { 215 | command_simple("kmacro_end", 0, 0) 216 | } 217 | 218 | kmacro_start_macro() 219 | { 220 | command_simple("kmacro_start", 0, 0) 221 | } 222 | 223 | kmacro_call_macro() 224 | { 225 | command_simple("kmacro_call", 0, 1) 226 | } 227 | 228 | kmacro_end_or_call_macro() 229 | { Global 230 | If kmacro_recoding 231 | kmacro_end_macro() 232 | Else 233 | kmacro_call_macro() 234 | } 235 | 236 | kmacro_end_and_call_macro() 237 | { Global 238 | run_hooks("pre_command_hook") 239 | If kmacro_recoding 240 | kmacro_end() 241 | Loop, % arg ? arg : 1 242 | kmacro_call() 243 | run_hooks("post_command_hook") 244 | } 245 | 246 | ;; ----- 247 | ;; files 248 | ;; ----- 249 | 250 | ;; save (C-s) 251 | save_buffer() 252 | { 253 | command_simple("^s", 0, 0) 254 | } 255 | 256 | ;; files(_F) > save as(_A) 257 | write_file() 258 | { 259 | command_simple("{alt down}fa{alt up}", 0, 0) 260 | } 261 | 262 | ;; open file (C-o) 263 | find_file() 264 | { 265 | command_simple("^o", 0, 0) 266 | } 267 | 268 | ;; launch explorer (Win-e) 269 | dired() 270 | { 271 | command_simple("#e", 0, 0) 272 | } 273 | 274 | ;; --------------- 275 | ;; windows, frames 276 | ;; --------------- 277 | 278 | ;; close window (M-F4) 279 | kill_frame() 280 | { 281 | command_simple("!{F4}", 0, 0) 282 | } 283 | 284 | ;; delete ARG tabs (C-F4) 285 | delete_window() 286 | { 287 | command_simple("^{f4}", 0, 1) 288 | } 289 | 290 | ;; new ARG tabs (C-t) 291 | split_window() 292 | { 293 | command_simple("^t", 0, 1) 294 | } 295 | 296 | ;; forward ARG tabs (C-TAB) 297 | next_window() 298 | { 299 | command_simple("^{tab}", 0, 1) 300 | } 301 | 302 | ;; backward ARG tabs (C-S-TAB) 303 | previous_window() 304 | { 305 | command_simple("^+{tab}", 0, 1) 306 | } 307 | 308 | ;; minimize frame (Win-Down) 309 | suspend_frame() 310 | { 311 | command_simple("#{down}", 0, 0) 312 | } 313 | 314 | ;; -------- 315 | ;; motion 316 | ;; -------- 317 | 318 | ;; forward ARG chars 319 | forward_char() 320 | { 321 | command_motion("{right}", 1) 322 | } 323 | 324 | ;; backward ARG chars 325 | backward_char() 326 | { 327 | command_motion("{left}", 1) 328 | } 329 | 330 | ;; forward ARG words (C-right) 331 | forward_word() 332 | { 333 | command_motion("^{right}", 1) 334 | } 335 | 336 | ;; backward ARG words (C-left) 337 | backward_word() 338 | { 339 | command_motion("^{left}", 1) 340 | } 341 | 342 | ;; down ARG lines 343 | next_line() 344 | { 345 | command_motion("{down}", 1) 346 | } 347 | 348 | ;; up ARG lines 349 | previous_line() 350 | { 351 | command_motion("{up}", 1) 352 | } 353 | 354 | ;; -------------- 355 | ;; jumping around 356 | ;; -------------- 357 | 358 | ;; PgDn ARG times 359 | scroll_down() 360 | { 361 | command_motion("{pgdn}", 1) 362 | } 363 | 364 | ;; PgUp ARG times 365 | scroll_up() 366 | { 367 | command_motion("{pgup}", 1) 368 | } 369 | 370 | ;; scroll left ARG times (Alt+PgUp) 371 | scroll_left() 372 | { 373 | command_motion("!{pgup}", 1) 374 | } 375 | 376 | ;; scroll right ARG times (Alt+PgDn) 377 | scroll_right() 378 | { 379 | command_motion("!{pgdn}", 1) 380 | } 381 | 382 | ;; Home 383 | move_beginning_of_line() 384 | { 385 | command_motion("{home}", 0) 386 | } 387 | 388 | ;; End 389 | move_end_of_line() 390 | { 391 | command_motion("{end}", 0) 392 | } 393 | 394 | ;; bob (C-Home) 395 | beginning_of_buffer() 396 | { 397 | command_motion("^{home}", 9) 398 | } 399 | 400 | ;; eob (C-End) 401 | end_of_buffer() 402 | { 403 | command_motion("^{end}", 0) 404 | } 405 | 406 | ;; move to the bob and forward N-1 lines 407 | goto_line() 408 | { 409 | run_hooks("pre_command_hook") 410 | InputBox, line, Goto:, , , 130, 105 411 | If line is number 412 | { 413 | line-- 414 | reset_mark() 415 | send("^{home}") 416 | Loop, %line% 417 | send("{down}") 418 | } 419 | run_hooks("post_command_hook") 420 | } 421 | 422 | ;; ------ 423 | ;; region 424 | ;; ------ 425 | 426 | ;; mark this word 427 | mark_word() 428 | { 429 | command_mark("^{right}{shift down}^{left}{shift up}") 430 | } 431 | 432 | ;; mark this line 433 | mark_whole_line() 434 | { 435 | command_mark("{home}{shift down}{end}{shift up}") 436 | } 437 | 438 | ;; mark this buffer 439 | mark_whole_buffer() 440 | { 441 | command_mark("^a") 442 | } 443 | 444 | ;; copy (C-c) 445 | kill_ring_save() 446 | { 447 | run_hooks("pre_command_hook") 448 | send("^c") 449 | reset_mark() 450 | kill_ring_push() 451 | run_hooks("post_command_hook") 452 | } 453 | 454 | ;; cut (C-x) 455 | kill_region() 456 | { 457 | command_simple("^x", 1, 0) 458 | kill_ring_push() 459 | } 460 | 461 | ;; paste ARG times (C-v) 462 | yank() 463 | { 464 | command_simple("^v", 1, 1) 465 | } 466 | 467 | ;; pop kill_ring ARG times (M-v) 468 | yank_pop() 469 | { 470 | run_hooks("pre_command_hook") 471 | send("^z") 472 | Loop, % arg ? arg : 1 473 | kill_ring_pop() 474 | send("^v") 475 | run_hooks("after_change_hook") 476 | run_hooks("post_command_hook") 477 | } 478 | 479 | ;; delete ARG chars forward (Del) 480 | delete_char() 481 | { 482 | command_simple("{del}", 1, 1) 483 | } 484 | 485 | ;; delete ARG chars backward (Bs) 486 | delete_backward_char() 487 | { 488 | command_simple("{bs}", 1, 1) 489 | } 490 | 491 | ;; delete ARG words "forward" 492 | kill_word() 493 | { 494 | command_abc("", "{shift down}^{right}{shift up}", "^x", 1) 495 | kill_ring_push() 496 | } 497 | 498 | ;; delete ARG words "backward" 499 | backward_kill_word() 500 | { 501 | command_abc("", "{shift down}^{left}{shift up}", "^x", 1) 502 | kill_ring_push() 503 | } 504 | 505 | ;; delete this line "forward" 506 | kill_line() 507 | { 508 | command_simple("{shift down}{end}{shift up}^x", 1, 0) 509 | kill_ring_push() 510 | } 511 | 512 | ;; delete whole line 513 | kill_whole_line() 514 | { 515 | command_simple("{home}{shift down}{end}{right}{shift up}^x", 1, 0) 516 | kill_ring_push() 517 | } 518 | 519 | ;; ------------------ 520 | ;; newline and indent 521 | ;; ------------------ 522 | 523 | ;; new ARG lines (Ret) 524 | newline() 525 | { 526 | command_simple("{enter}", 1, 1) 527 | } 528 | 529 | ;; open ARG lines below (Ret, Left) 530 | open_line() 531 | { 532 | command_simple("{enter}{left}", 1, 1) 533 | } 534 | 535 | ;; indent ARG times (Tab) 536 | indent_for_tab_command() 537 | { 538 | command_simple("{tab}", 1, 1) 539 | } 540 | 541 | ;; join ARG lines backward 542 | delete_indentation() 543 | { 544 | command_simple("{home}{bs}", 1, 1) 545 | } 546 | 547 | ;; ------------- 548 | ;; edit commands 549 | ;; ------------- 550 | 551 | ;; undo ARG times (C-z) 552 | undo_only() 553 | { 554 | command_simple("^z", 1, 1) 555 | } 556 | 557 | ;; redo ARG times (C-y) 558 | redo() 559 | { 560 | command_simple("^y", 1, 1) 561 | } 562 | 563 | ;; transpose ARG chars 564 | transpose_chars() 565 | { 566 | command_abc("{left}{shift down}{right}{shift up}^x", "{right}", "^v", 1) 567 | kill_ring_restore() 568 | } 569 | 570 | ;; transpose ARG words 571 | transpose_words() 572 | { 573 | command_abc("{left}^{right}{shift down}^{left}{shift up}^x", "^{right}", "^v", 1) 574 | kill_ring_restore() 575 | } 576 | 577 | ;; transpose ARG lines 578 | transpose_lines() 579 | { 580 | command_abc("{up}{home}{shift down}{down}{shift up}^x", "{down}", "^v", 1) 581 | kill_ring_restore() 582 | } 583 | 584 | ;; replace (C-h) 585 | query_replace() 586 | { 587 | command_simple("^h", 0, 0) 588 | } 589 | 590 | ;; search (C-f) 591 | search_forward() 592 | { 593 | command_simple("^f", 0, 0) 594 | } 595 | 596 | ;; insert mode (ins) 597 | overwrite_mode() 598 | { 599 | command_simple("{insert}", 0, 0) 600 | } 601 | 602 | ;; --------------- 603 | ;; case conversion 604 | ;; --------------- 605 | 606 | upcase_region() 607 | { 608 | run_hooks("pre_command_hook") 609 | safe_cut() 610 | StringUpper, Clipboard, Clipboard 611 | send("^v") 612 | run_hooks("after_change_hook") 613 | run_hooks("post_command_hook") 614 | } 615 | 616 | downcase_region() 617 | { 618 | run_hooks("pre_command_hook") 619 | safe_cut() 620 | StringLower, Clipboard, Clipboard 621 | send("^v") 622 | run_hooks("after_change_hook") 623 | run_hooks("post_command_hook") 624 | } 625 | 626 | upcase_word() 627 | { 628 | run_hooks("pre_command_hook") 629 | send("^{right}{shift down}^{left}{shift up}") 630 | safe_cut() 631 | StringUpper, Clipboard, Clipboard 632 | send("^v") 633 | run_hooks("after_change_hook") 634 | run_hooks("post_command_hook") 635 | } 636 | 637 | downcase_word() 638 | { 639 | run_hooks("pre_command_hook") 640 | send("^{right}{shift down}^{left}{shift up}") 641 | safe_cut() 642 | StringLower, Clipboard, Clipboard 643 | send("^v") 644 | run_hooks("after_change_hook") 645 | run_hooks("post_command_hook") 646 | } 647 | 648 | capitalize_word() 649 | { 650 | run_hooks("pre_command_hook") 651 | send("{shift down}^{right}{shift up}") 652 | safe_cut() 653 | StringUpper, Clipboard, Clipboard, T 654 | send("^v") 655 | run_hooks("after_change_hook") 656 | run_hooks("post_command_hook") 657 | } 658 | 659 | ;; --------------- 660 | ;; inserting pairs 661 | ;; --------------- 662 | 663 | ;; insert ARG parentheses 664 | insert_parentheses() 665 | { 666 | command_pair("(){left}") 667 | } 668 | 669 | ;; insert comment (/* `!!' */) 670 | insert_comment() 671 | { 672 | command_pair("/* */{left}{left}{left}") 673 | } 674 | 675 | ;; continue multiline comment ARG lines (\n * `!!') 676 | indent_new_comment_line() 677 | { 678 | command_simple("{enter} *{space}", 1, 1) 679 | } 680 | 681 | ;; ------ 682 | ;; others 683 | ;; ------ 684 | 685 | ;; launch cmd.exe 686 | shell() 687 | { 688 | run_hooks("pre_command_hook") 689 | Run, cmd.exe 690 | run_hooks("after_display_transition_hook") 691 | run_hooks("post_command_hook") 692 | } 693 | 694 | ;; execute shell command (Win-r) 695 | shell_command() 696 | { 697 | command_simple("#r", 0, 0) 698 | } 699 | 700 | ;; add text properties (basically for MSWord) 701 | facemenu() 702 | { 703 | command_simple("^d", 0, 0) 704 | } 705 | 706 | ;; help 707 | help() 708 | { 709 | command_simple("{f1}", 0, 0) 710 | } 711 | -------------------------------------------------------------------------------- /commands_util.ahk: -------------------------------------------------------------------------------- 1 | ;; This script provides: command skeletons 2 | 3 | ;; 4 | 5 | ;; command_simple(str, [causechange 0], [repeatable 0]) 6 | ;; ... send string as a command (when causechange is t, call after_change_hook) 7 | 8 | ;; command_motion(str, [repeatable 0]) 9 | ;; ... send string as a command that can expand the region 10 | 11 | ;; ----------------- 12 | ;; command skeletons 13 | ;; ----------------- 14 | 15 | ;; command_str(str, moves = 0, changes = 0, repeatable = 0, prestr = "", poststr = "") 16 | ;; { Global 17 | ;; Local sendstr = make_str(str, (arg && repeatable) ? arg 1) 18 | ;; If (moves && mark) 19 | ;; sendstr = {shift down}%sendstr%{shift up} 20 | ;; run_hooks("pre_command_hook") 21 | ;; send(sendstr) 22 | ;; run_hooks("post_command_hook") 23 | ;; } 24 | 25 | ;; command_function(fnname, changes = 0, repeatable = 0) 26 | ;; { Global 27 | ;; run_hooks("pre_command_hook") 28 | ;; Loop, % (arg && repeatable) ? arg : 1 29 | ;; funcall(fnname) 30 | ;; If changes 31 | ;; run_hooks("after_change_hook") 32 | ;; run_hooks("post_command_hook") 33 | ;; } 34 | 35 | ;; command that simply sends a key or calls a function 36 | ;; WILL BE OBSOLETE 37 | command_simple(str, changes, repeatable) 38 | { Global 39 | run_hooks("pre_command_hook") 40 | If isFunc(str) 41 | Loop, % (arg && repeatable) ? arg : 1 42 | %str%() 43 | Else 44 | Loop, % (arg && repeatable) ? arg : 1 45 | send(str) 46 | If changes 47 | run_hooks("after_change_hook") 48 | run_hooks("post_command_hook") 49 | } 50 | 51 | ;; a command that moves cursor position 52 | ;; WILL BE OBSOLETE 53 | command_motion(str, repeatable) 54 | { Global 55 | run_hooks("pre_command_hook") 56 | If mark 57 | str = {shift down}%str%{shift up} 58 | Loop, % (arg && repeatable) ? arg : 1 59 | send(str) 60 | run_hooks("post_command_hook") 61 | } 62 | 63 | ;; WILL BE OBSOLETE 64 | command_abc(a, b, c, change) 65 | { Global 66 | run_hooks("pre_command_hook") 67 | send(a) 68 | Loop, % arg ? arg : 1 69 | send(b) 70 | send(c) 71 | If change 72 | run_hooks("after_change_hook") 73 | run_hooks("post_command_hook") 74 | } 75 | 76 | ;; command that inserts a balanced expression 77 | command_pair(str) 78 | { Global 79 | run_hooks("pre_command_hook") 80 | If mark 81 | send("^x") 82 | Loop, % arg ? arg : 1 83 | send(str) 84 | If mark 85 | send("^v") 86 | run_hooks("after_change_hook") 87 | run_hooks("post_command_hook") 88 | } 89 | 90 | ;; command that selects something 91 | command_mark(str) 92 | { 93 | run_hooks("pre_command_hook") 94 | send(str) 95 | set_mark() 96 | run_hooks("post_command_hook") 97 | } 98 | -------------------------------------------------------------------------------- /ewow.ahk: -------------------------------------------------------------------------------- 1 | #Include fundamental.ahk 2 | #Include prefix.ahk 3 | #Include commands.ahk 4 | #Include init.ahk 5 | #Include keybinds.ahk 6 | -------------------------------------------------------------------------------- /fundamental.ahk: -------------------------------------------------------------------------------- 1 | ;; This script provides: fundamental functions, environment 2 | 3 | ;; 4 | 5 | ;; - foreach(list, fnname) ... apply function to all elements in a list 6 | ;; - add_to_list(listname, element) ... add an element to a list 7 | ;; - remove_from_list(listname, element) ... remove an element from a list 8 | 9 | ;; - make_str(str, n) ... repeat str n-times 10 | 11 | ;; - funcall(fnname) ... call fucntion with no arguments 12 | 13 | ;; 14 | 15 | ;; - ignored_frame() ... decide if EWOW should be quiet 16 | ;; => configure with "ignored_frames" variable 17 | 18 | ;; - alloc_tt() ... get an id for ToolTip 19 | 20 | ;; 21 | 22 | ;; - send(str) ... a wrapper function of "Send", either call STR as a function or send STR 23 | ;; => ALWAYS USE THIS FUNCTION TO INTERACT WITH WINDOWS, SO THAT IT'S RECORDED IN MACROS 24 | 25 | ;; - read_char() ... steal one event from send() and return it 26 | 27 | ;; 28 | 29 | ;; - pre_command_hook ... all commands must run at the very beginning 30 | ;; - post_command_hook ... all commands must run at the very end 31 | ;; - after_change_hook ... all commands must run just after changes 32 | ;; => use "run_hooks" to run 33 | 34 | ;; - before_send_hook ... automatically run before send() 35 | ;; - after_send_hook ... automatically run after send() 36 | ;; - after_display_transition_hook ... automatically run after display transitions 37 | ;; => run automatically 38 | 39 | ;; - add_hook(hookname, fnname) ... add a function to a hook 40 | ;; - remove_hook(hookname, fnname) ... remove a function from a hook 41 | ;; - run_hooks(hookname) ... run all functions in a hook 42 | 43 | ;; 44 | 45 | ;; - last_command ... the last event (being) sent with send() 46 | ;; => you may assume that this variable is already updated in before_send_hook 47 | 48 | ;; 49 | 50 | ;; - ignored_frames ... list of window-classes in which EWOW should be quiet 51 | 52 | ;; -------------- 53 | ;; (AHK Tutorial) 54 | ;; -------------- 55 | 56 | ;; funname() 57 | ;; { Global <- use global variables 58 | ;; Local foo <- but keep variable "foo" local 59 | ;; foo = foo <- set foo to a string literal "foo" 60 | ;; foo = %foo% <- set foo to a foo's value 61 | ;; foo := foo <- (equivalent) 62 | ;; foo = %foo%bar <- concatenate foo's value and a string literal "bar" 63 | ;; foo .= bar <- (equivalent) 64 | ;; MsgBox foo is %foo% <- call command MsgBox with "foo is %foo%" 65 | ;; MsgBox % "foo is " . foo <- equivalent to the previous line 66 | ;; message("foo is " . foo) <- call function message with "foo is %foo%" 67 | ;; message(foo is %foo%) <- (NO GOOD) 68 | ;; } 69 | 70 | ;; ------------------ 71 | ;; AHK configurations 72 | ;; ------------------ 73 | 74 | #NoEnv 75 | #InstallKeybdHook 76 | #InstallMouseHook 77 | #UseHook 78 | #MaxHotkeysPerInterval 100 79 | 80 | SetBatchLines, -1 81 | SetKeyDelay, 0 82 | Sendmode, Event 83 | CoordMode, Mouse, Screen 84 | 85 | ;; ----------------- 86 | ;; Utility Functions 87 | ;; ----------------- 88 | 89 | foreach(list, fnname) 90 | { Global 91 | Loop, Parse, list, `,, `r `n 92 | %fnname%(A_LoopField) 93 | } 94 | 95 | add_to_list(listname, element) 96 | { Global 97 | Local list 98 | list := %listname% ; list = (eval (symbol-value 'listname)) 99 | If element in %list% 100 | Return 101 | If list != 102 | %listname% = %list%,%element% 103 | Else 104 | %listname% = %element% 105 | } 106 | 107 | remove_from_list(listname, element) 108 | { Global 109 | Local list, regex 110 | list := %listname% 111 | regex = ,?%element% 112 | %listname% := RegExReplace(list, regex, "") 113 | } 114 | 115 | funcall(fnname) 116 | { Global 117 | If isFunc(fnname) 118 | %fnname%() 119 | } 120 | 121 | make_str(str, n) 122 | { 123 | out = 124 | Loop, %n% 125 | out .= str 126 | Return out 127 | } 128 | 129 | ;; ----- 130 | ;; Hooks 131 | ;; ----- 132 | 133 | pre_command_hook = 134 | post_command_hook = 135 | after_change_hook = 136 | ;; => call manually 137 | 138 | before_send_hook = 139 | after_send_hook = 140 | ;; => called by send() 141 | 142 | after_display_transition_hook = 143 | ;; => called on WinEventHook 144 | 145 | run_hooks(hookname) 146 | { Global 147 | foreach(%hookname%, "funcall") 148 | } 149 | 150 | remove_hook(hookname, fnname) 151 | { 152 | remove_from_list(hookname, fnname) 153 | } 154 | 155 | add_hook(hookname, fnname) 156 | { 157 | add_to_list(hookname, fnname) 158 | } 159 | 160 | ;; ---- 161 | ;; Send 162 | ;; ---- 163 | 164 | read_char_waiting = 0 165 | last_command = 166 | 167 | ;; a wrapper function of "Send" 168 | send(str) 169 | { Global 170 | last_command := str 171 | run_hooks("before_send_hook") 172 | If read_char_waiting 173 | read_char_waiting = 0 174 | Else If isFunc(last_command) 175 | %last_command%() 176 | Else 177 | Send, %last_command% 178 | run_hooks("after_send_hook") 179 | } 180 | 181 | read_char() 182 | { Global 183 | read_char_waiting = 1 184 | While read_char_waiting 185 | {} 186 | Return last_command 187 | } 188 | 189 | ;; ------------------------- 190 | ;; Detect Display Transition 191 | ;; ------------------------- 192 | 193 | ;; taken from 194 | ;; https://sites.google.com/site/agkh6mze/howto/winevent 195 | 196 | dt_callback(a, b, c, d, e, f, g) 197 | { 198 | run_hooks("after_display_transition_hook") 199 | } 200 | 201 | dt_event_proc := RegisterCallback("dt_callback") 202 | 203 | DllCall("SetWinEventHook" 204 | , "UInt", 0x00000003, "UInt", 0x00000003, "UInt", 0 205 | , "UInt", dt_event_proc, "UInt", 0, "UInt", 0, "UInt", 0x0003, "UInt") 206 | 207 | ;; -------------- 208 | ;; Ignored Frames 209 | ;; -------------- 210 | 211 | ignored_frames = ConsoleWindowClass,cygwin/x X rl-xterm-XTerm-0,mintty,MEADOW,Vim,Emacs,XEmacs,SunAwtFrame,Xming X,VMPlayerFrame,VirtualConsoleClass 212 | 213 | ;; decide if ewow should be quiet 214 | ignored_frame() 215 | { Global 216 | Local class 217 | WinGetClass, class, A 218 | If class in %ignored_frames% 219 | Return 1 220 | Else 221 | Return 0 222 | } 223 | 224 | ;; ----------------- 225 | ;; Manage ToolTip ID 226 | ;; ----------------- 227 | 228 | ;; alloc_tt() allocates an id for the new ToolTip 229 | ;; and returns it 230 | 231 | tt_count = 0 232 | 233 | alloc_tt() 234 | { Global 235 | tt_count++ 236 | Return tt_count 237 | } 238 | -------------------------------------------------------------------------------- /init.ahk: -------------------------------------------------------------------------------- 1 | ;; load libraries 2 | ;; -------------- 3 | 4 | ;; #Include lib_evil.ahk 5 | ;; #Include lib_autopair.ahk 6 | 7 | ;; customize variables 8 | ;; ------------------- 9 | 10 | ;; evil_auto_mode = 1 11 | 12 | ;; //////////// auto execution section ends here //////////// 13 | 14 | ;; keybinds for lib_autopair 15 | ;; ------------------------- 16 | 17 | ;; #If !ignored_frame() && !cx 18 | ;; ,:: smart_colon() 19 | ;; [:: smart_bracket() 20 | ;; +9:: insert_parentheses() 21 | ;; +[:: smart_brace() 22 | ;; +':: smart_dquot() 23 | 24 | ;; keybinds for lib_evil 25 | ;; --------------------- 26 | 27 | ;; #If !ignored_frame() && !evil 28 | ;; escape:: evil_mode() 29 | 30 | ;; #If !dummy && !ignored_frame() && evil 31 | ;; bs:: self_send_command() 32 | ;; enter:: self_send_command() 33 | ;; space:: self_send_command() 34 | 35 | ;; #Include lib_evil_keys.ahk 36 | -------------------------------------------------------------------------------- /keybinds.ahk: -------------------------------------------------------------------------------- 1 | ;; *** CAUTION: LOAD THIS SCRIPT AT THE LAST *** 2 | ;; This script provides: default keybinds 3 | 4 | ;; condition "!dummy" is added to prevent error "duplicate hotkeys" 5 | 6 | ;; ---------------- 7 | ;; AltTab detection 8 | ;; ---------------- 9 | 10 | #If, alt_pressed 11 | alt up:: alttab_end() 12 | #If, 13 | !tab:: alttab_next() 14 | 15 | ;; --------------- 16 | ;; C-x C- bindings 17 | ;; --------------- 18 | #If !dummy && !ignored_frame() && cx 19 | 20 | ^`:: ignore() 21 | ^1:: ignore() 22 | ^2:: ignore() 23 | ^3:: ignore() 24 | ^4:: ignore() 25 | ^5:: ignore() 26 | ^6:: ignore() 27 | ^7:: ignore() 28 | ^8:: ignore() 29 | ^9:: ignore() 30 | ^0:: ignore() ; * text-scale-adjust 31 | ^-:: ignore() ; * text-scale-adjust 32 | ^=:: ignore() ; * text-scale-adjust 33 | ^q:: ignore() 34 | ^w:: write_file() 35 | ^e:: ignore() 36 | ^r:: find_file() ; find-file-read-only 37 | ^t:: transpose_lines() ; transpose-lines 38 | ^y:: ignore() 39 | ^u:: upcase_region() 40 | ^i:: ignore() 41 | ^o:: ignore() 42 | ^p:: ignore() 43 | ^[:: ignore() 44 | ^]:: ignore() 45 | ^a:: ignore() 46 | ^s:: save_buffer() 47 | ^d:: dired() ; list-directory 48 | ^f:: find_file() 49 | ^g:: ignore() 50 | ^h:: ignore() 51 | ^j:: ignore() 52 | ^k:: ignore() 53 | ^l:: downcase_region() 54 | ^`;:: ignore() 55 | ^':: ignore() 56 | ^\:: ignore() 57 | ^z:: suspend_frame() ; suspend-frame 58 | ^x:: ignore() 59 | ^c:: kill_frame() ; save-buffers-kill-emacs 60 | ^v:: find_file() ; find-alternate-file 61 | ^b:: ignore() 62 | ^n:: ignore() 63 | ^m:: ignore() 64 | ^,:: ignore() 65 | ^.:: ignore() 66 | ^/:: ignore() 67 | 68 | ^left:: previous_window() ; previous-buffer 69 | ^right:: next_window() ; next-buffer 70 | 71 | ;; ------------------- 72 | ;; C-x Shift- bindings 73 | ;; ------------------- 74 | #If !dummy && !ignored_frame() && cx 75 | 76 | +`:: ignore() 77 | +1:: ignore() 78 | +2:: ignore() 79 | +3:: ignore() 80 | +4:: ignore() 81 | +5:: ignore() 82 | +6:: ignore() 83 | +7:: ignore() 84 | +8:: ignore() 85 | +9:: kmacro_start_macro() 86 | +0:: kmacro_end_macro() 87 | +-:: ignore() 88 | +=:: ignore() 89 | +q:: ignore() 90 | +w:: ignore() 91 | +e:: ignore() 92 | +r:: ignore() 93 | +t:: ignore() 94 | +y:: ignore() 95 | +u:: ignore() 96 | +i:: ignore() 97 | +o:: ignore() 98 | +p:: ignore() 99 | +[:: ignore() 100 | +]:: ignore() 101 | +a:: ignore() 102 | +s:: ignore() 103 | +d:: ignore() 104 | +f:: ignore() 105 | +g:: ignore() 106 | +h:: ignore() 107 | +j:: ignore() 108 | +k:: ignore() 109 | +l:: ignore() 110 | +`;:: ignore() 111 | +':: ignore() 112 | +\:: ignore() 113 | +z:: ignore() 114 | +x:: ignore() 115 | +c:: ignore() 116 | +v:: ignore() 117 | +b:: ignore() 118 | +n:: ignore() 119 | +m:: ignore() 120 | +,:: scroll_left() 121 | +.:: scroll_right() 122 | +/:: ignore() 123 | 124 | ;; ------------ 125 | ;; C-x bindings 126 | ;; ------------ 127 | #If !dummy && !ignored_frame() && cx 128 | 129 | `:: ignore() 130 | 1:: ignore() ; * delete-other-windows 131 | 2:: split_window() ; split-window-vertically 132 | 3:: split_window() ; split-window-horizontally 133 | 4:: ignore() 134 | 5:: ignore() 135 | 6:: ignore() 136 | 7:: ignore() 137 | 8:: ignore() 138 | 9:: ignore() 139 | 0:: delete_window() 140 | -:: ignore() 141 | =:: ignore() 142 | q:: ignore() ; * kbd-macro-query 143 | w:: ignore() 144 | e:: kmacro_end_and_call_macro() 145 | r:: redo() ; ignore 146 | t:: ignore() 147 | y:: ignore() 148 | u:: undo_only() 149 | i:: ignore() 150 | o:: next_window() ; other-window 151 | p:: ignore() 152 | [:: ignore() 153 | ]:: ignore() 154 | a:: ignore() 155 | s:: ignore() 156 | d:: dired() 157 | f:: ignore() 158 | g:: ignore() 159 | h:: mark_whole_buffer() 160 | j:: ignore() 161 | k:: delete_window() ; kill-buffer 162 | l:: ignore() 163 | `;:: ignore() 164 | ':: ignore() 165 | \:: ignore() 166 | z:: repeat() 167 | x:: ignore() 168 | c:: ignore() 169 | v:: ignore() 170 | b:: ignore() 171 | n:: ignore() 172 | m:: ignore() 173 | ,:: ignore() 174 | .:: ignore() 175 | /:: ignore() 176 | 177 | left:: previous_window() ; previous-buffer 178 | right:: next_window() ; next-buffer 179 | 180 | ;; ------------------- 181 | ;; C-M-Shift- bindings 182 | ;; ------------------- 183 | #If !dummy && !ignored_frame() && !cx 184 | 185 | !^+`:: self_insert_command() 186 | !^+1:: self_insert_command() 187 | !^+2:: self_insert_command() 188 | !^+3:: self_insert_command() 189 | !^+4:: self_insert_command() 190 | !^+5:: query_replace() ; query-replace-regexp 191 | !^+6:: self_insert_command() 192 | !^+7:: self_insert_command() 193 | !^+8:: self_insert_command() 194 | !^+9:: self_insert_command() 195 | !^+0:: self_insert_command() 196 | !^+-:: self_insert_command() 197 | !^+=:: self_insert_command() 198 | !^+q:: self_insert_command() 199 | !^+w:: self_insert_command() 200 | !^+e:: self_insert_command() 201 | !^+r:: self_insert_command() 202 | !^+t:: self_insert_command() 203 | !^+y:: self_insert_command() 204 | !^+u:: self_insert_command() 205 | !^+i:: self_insert_command() 206 | !^+o:: self_insert_command() 207 | !^+p:: self_insert_command() 208 | !^+[:: self_insert_command() 209 | !^+]:: self_insert_command() 210 | !^+a:: self_insert_command() 211 | !^+s:: self_insert_command() 212 | !^+d:: self_insert_command() 213 | !^+f:: self_insert_command() 214 | !^+g:: self_insert_command() 215 | !^+h:: self_insert_command() 216 | !^+j:: self_insert_command() 217 | !^+k:: self_insert_command() 218 | !^+l:: self_insert_command() 219 | !^+`;:: self_insert_command() 220 | !^+':: self_insert_command() 221 | !^+\:: self_insert_command() 222 | !^+z:: self_insert_command() 223 | !^+x:: self_insert_command() 224 | !^+c:: self_insert_command() 225 | !^+v:: self_insert_command() 226 | !^+b:: self_insert_command() 227 | !^+n:: self_insert_command() 228 | !^+m:: self_insert_command() 229 | !^+,:: self_insert_command() 230 | !^+.:: self_insert_command() 231 | !^+/:: self_insert_command() 232 | 233 | ;; ------------- 234 | ;; C-M- bindings 235 | ;; ------------- 236 | #If !dummy && !ignored_frame() && !cx 237 | 238 | !^`:: self_insert_command() 239 | !^1:: digit_argument() 240 | !^2:: digit_argument() 241 | !^3:: digit_argument() 242 | !^4:: digit_argument() 243 | !^5:: digit_argument() 244 | !^6:: digit_argument() 245 | !^7:: digit_argument() 246 | !^8:: digit_argument() 247 | !^9:: digit_argument() 248 | !^0:: digit_argument() 249 | !^-:: self_insert_command() 250 | !^=:: self_insert_command() 251 | !^q:: self_insert_command() 252 | !^w:: self_insert_command() 253 | !^e:: self_insert_command() 254 | !^r:: search_forward() ; isearch-backward-regexp 255 | !^t:: self_insert_command() 256 | !^y:: self_insert_command() 257 | !^u:: self_insert_command() 258 | !^i:: self_insert_command() 259 | !^o:: self_insert_command() 260 | !^p:: self_insert_command() 261 | !^[:: self_insert_command() 262 | !^]:: self_insert_command() 263 | !^a:: self_insert_command() 264 | !^s:: search_forward() ; isearch-forward-regexp 265 | !^d:: self_insert_command() 266 | !^f:: self_insert_command() 267 | !^g:: self_insert_command() 268 | !^h:: self_insert_command() 269 | !^j:: indent_new_comment_line() 270 | !^k:: self_insert_command() 271 | !^l:: self_insert_command() 272 | !^`;:: self_insert_command() 273 | !^':: self_insert_command() 274 | !^\:: self_insert_command() 275 | !^z:: self_insert_command() 276 | !^x:: self_insert_command() 277 | !^c:: self_insert_command() 278 | !^v:: self_insert_command() 279 | !^b:: self_insert_command() 280 | !^n:: self_insert_command() 281 | !^m:: self_insert_command() 282 | !^,:: self_insert_command() 283 | !^.:: self_insert_command() 284 | !^/:: self_insert_command() 285 | 286 | ;; ----------------- 287 | ;; M-Shift- bindings 288 | ;; ----------------- 289 | #If !dummy && !ignored_frame() && !cx 290 | 291 | !+`:: self_insert_command() 292 | !+1:: shell_command() 293 | !+2:: mark_word() 294 | !+3:: self_insert_command() 295 | !+4:: self_insert_command() 296 | !+5:: query_replace() 297 | !+6:: delete_indentation() 298 | !+7:: shell_command() ; async-shell-command 299 | !+8:: self_insert_command() 300 | !+9:: insert_parentheses() 301 | !+0:: self_insert_command() 302 | !+-:: self_insert_command() 303 | !+=:: self_insert_command() 304 | !+q:: self_insert_command() 305 | !+w:: self_insert_command() 306 | !+e:: self_insert_command() 307 | !+r:: self_insert_command() 308 | !+t:: self_insert_command() 309 | !+y:: self_insert_command() 310 | !+u:: self_insert_command() 311 | !+i:: self_insert_command() 312 | !+o:: self_insert_command() 313 | !+p:: self_insert_command() 314 | !+[:: scroll_up() ; backward-paragraph 315 | !+]:: scroll_down() ; forward-paragraph 316 | !+a:: self_insert_command() 317 | !+s:: self_insert_command() 318 | !+d:: self_insert_command() 319 | !+f:: self_insert_command() 320 | !+g:: self_insert_command() 321 | !+h:: self_insert_command() 322 | !+j:: self_insert_command() 323 | !+k:: self_insert_command() 324 | !+l:: self_insert_command() 325 | !+`;:: self_insert_command() 326 | !+':: self_insert_command() 327 | !+\:: self_insert_command() 328 | !+z:: self_insert_command() 329 | !+x:: self_insert_command() 330 | !+c:: self_insert_command() 331 | !+v:: self_insert_command() 332 | !+b:: self_insert_command() 333 | !+n:: self_insert_command() 334 | !+m:: self_insert_command() 335 | !+,:: beginning_of_buffer() 336 | !+.:: end_of_buffer() 337 | !+/:: self_insert_command() 338 | 339 | ;; ----------- 340 | ;; M- bindings 341 | ;; ----------- 342 | #If !dummy && !ignored_frame() && !cx 343 | 344 | !`:: self_insert_command() 345 | !1:: digit_argument() 346 | !2:: digit_argument() 347 | !3:: digit_argument() 348 | !4:: digit_argument() 349 | !5:: digit_argument() 350 | !6:: digit_argument() 351 | !7:: digit_argument() 352 | !8:: digit_argument() 353 | !9:: digit_argument() 354 | !0:: digit_argument() 355 | !-:: self_insert_command() 356 | !=:: self_insert_command() 357 | !q:: self_insert_command() 358 | !w:: kill_ring_save() 359 | !e:: move_end_of_line() ; forward-sentence 360 | !r:: self_insert_command() 361 | !t:: transpose_words() 362 | !y:: yank_pop() 363 | !u:: upcase_word() 364 | !i:: indent_for_tab_command() ; tab-to-tab-stop 365 | !o:: facemenu() ; (prefix) 366 | !p:: self_insert_command() 367 | ![:: self_insert_command() 368 | !]:: self_insert_command() 369 | !a:: move_beginning_of_line() ; backward-sentence 370 | !s:: self_insert_command() 371 | !d:: kill_word() 372 | !f:: forward_word() 373 | !g:: goto_line() ; (prefix) 374 | !h:: self_insert_command() 375 | !j:: indent_new_comment_line() 376 | !k:: self_insert_command() 377 | !l:: downcase_word() 378 | !`;:: insert_comment() ; comment-dwim 379 | !':: self_insert_command() 380 | !\:: self_insert_command() 381 | !z:: delete_char() ; zap-to-char 382 | !x:: self_insert_command() 383 | !c:: capitalize_word() 384 | !v:: scroll_down() 385 | !b:: backward_word() 386 | !n:: self_insert_command() 387 | !m:: move_beginning_of_line() ; back-to-indentation 388 | !,:: self_insert_command() 389 | !.:: self_insert_command() 390 | !/:: self_insert_command() 391 | 392 | !bs:: backward_kill_word() 393 | !left:: backward_word() 394 | !right:: forward_word() 395 | !f4:: kill_frame() ; save-buffers-kill-emacs 396 | 397 | ;; ----------------- 398 | ;; C-Shift- bindings 399 | ;; ----------------- 400 | #If !dummy && !ignored_frame() && !cx 401 | 402 | ^+`:: self_insert_command() 403 | ^+1:: self_insert_command() 404 | ^+2:: set_mark_command() 405 | ^+3:: self_insert_command() 406 | ^+4:: self_insert_command() 407 | ^+5:: self_insert_command() 408 | ^+6:: self_insert_command() 409 | ^+7:: self_insert_command() 410 | ^+8:: self_insert_command() 411 | ^+9:: self_insert_command() 412 | ^+0:: self_insert_command() 413 | ^+-:: undo_only() 414 | ^+=:: self_insert_command() 415 | ^+q:: self_insert_command() 416 | ^+w:: self_insert_command() 417 | ^+e:: self_insert_command() 418 | ^+r:: self_insert_command() 419 | ^+t:: self_insert_command() 420 | ^+y:: self_insert_command() 421 | ^+u:: self_insert_command() 422 | ^+i:: self_insert_command() 423 | ^+o:: self_insert_command() 424 | ^+p:: self_insert_command() 425 | ^+[:: self_insert_command() 426 | ^+]:: self_insert_command() 427 | ^+a:: self_insert_command() 428 | ^+s:: self_insert_command() 429 | ^+d:: self_insert_command() 430 | ^+f:: self_insert_command() 431 | ^+g:: self_insert_command() 432 | ^+h:: self_insert_command() 433 | ^+j:: self_insert_command() 434 | ^+k:: self_insert_command() 435 | ^+l:: self_insert_command() 436 | ^+`;:: self_insert_command() 437 | ^+':: self_insert_command() 438 | ^+\:: self_insert_command() 439 | ^+z:: self_insert_command() 440 | ^+x:: self_insert_command() 441 | ^+c:: self_insert_command() 442 | ^+v:: self_insert_command() 443 | ^+b:: self_insert_command() 444 | ^+n:: self_insert_command() 445 | ^+m:: self_insert_command() 446 | ^+,:: self_insert_command() 447 | ^+.:: self_insert_command() 448 | ^+/:: self_insert_command() 449 | 450 | ^+bs:: kill_whole_line() 451 | 452 | ;; ----------- 453 | ;; C- bindings 454 | ;; ----------- 455 | #If !dummy && !ignored_frame() && !cx 456 | 457 | ^`:: self_insert_command() 458 | ^1:: digit_argument() 459 | ^2:: digit_argument() 460 | ^3:: digit_argument() 461 | ^4:: digit_argument() 462 | ^5:: digit_argument() 463 | ^6:: digit_argument() 464 | ^7:: digit_argument() 465 | ^8:: digit_argument() 466 | ^9:: digit_argument() 467 | ^0:: digit_argument() 468 | ^-:: self_insert_command() 469 | ^=:: self_insert_command() 470 | ^q:: self_insert_command() 471 | ^w:: kill_region() 472 | ^e:: move_end_of_line() 473 | ^r:: search_forward() ; isearch-backward 474 | ^t:: transpose_chars() 475 | ^y:: yank() 476 | ^u:: self_insert_command() 477 | ^i:: self_insert_command() 478 | ^o:: open_line() 479 | ^p:: previous_line() 480 | ^[:: self_insert_command() 481 | ^]:: self_insert_command() 482 | ^a:: move_beginning_of_line() 483 | ^s:: search_forward() ; isearch-forward 484 | ^d:: delete_char() 485 | ^f:: forward_char() 486 | ^g:: keyboard_quit() 487 | ^h:: help() 488 | ^j:: newline() ; newline-and-indent 489 | ^k:: kill_line() 490 | ^l:: self_insert_command() 491 | ^`;:: self_insert_command() 492 | ^':: self_insert_command() 493 | ^\:: self_insert_command() 494 | ^z:: suspend_frame() 495 | ^x:: set_cx_command() 496 | ^c:: self_insert_command() 497 | ^v:: scroll_up() 498 | ^b:: backward_char() 499 | ^n:: next_line() 500 | ^m:: self_insert_command() 501 | ^,:: self_insert_command() 502 | ^.:: self_insert_command() 503 | ^/:: undo_only() 504 | 505 | ^space:: set_mark_command() 506 | ^bs:: backward_kill_word() 507 | ^delete:: kill_word() 508 | ^up:: scroll_up() ; backward-paragraph 509 | ^down:: scroll_down() ; forward-paragraph 510 | ^left:: backward_word() 511 | ^right:: forward_word() 512 | ^end:: end_of_buffer() 513 | ^home:: beginning_of_buffer() 514 | ^insert:: kill_ring_save() 515 | 516 | ;; --------------- 517 | ;; Shift- bindings 518 | ;; --------------- 519 | #If !dummy && !ignored_frame() && !cx 520 | 521 | +`:: self_insert_command() 522 | +1:: self_insert_command() 523 | +2:: self_insert_command() 524 | +3:: self_insert_command() 525 | +4:: self_insert_command() 526 | +5:: self_insert_command() 527 | +6:: self_insert_command() 528 | +7:: self_insert_command() 529 | +8:: self_insert_command() 530 | +9:: self_insert_command() 531 | +0:: self_insert_command() 532 | +-:: self_insert_command() 533 | +=:: self_insert_command() 534 | +q:: self_insert_command() 535 | +w:: self_insert_command() 536 | +e:: self_insert_command() 537 | +r:: self_insert_command() 538 | +t:: self_insert_command() 539 | +y:: self_insert_command() 540 | +u:: self_insert_command() 541 | +i:: self_insert_command() 542 | +o:: self_insert_command() 543 | +p:: self_insert_command() 544 | +[:: self_insert_command() 545 | +]:: self_insert_command() 546 | +a:: self_insert_command() 547 | +s:: self_insert_command() 548 | +d:: self_insert_command() 549 | +f:: self_insert_command() 550 | +g:: self_insert_command() 551 | +h:: self_insert_command() 552 | +j:: self_insert_command() 553 | +k:: self_insert_command() 554 | +l:: self_insert_command() 555 | +`;:: self_insert_command() 556 | +':: self_insert_command() 557 | +\:: self_insert_command() 558 | +z:: self_insert_command() 559 | +x:: self_insert_command() 560 | +c:: self_insert_command() 561 | +v:: self_insert_command() 562 | +b:: self_insert_command() 563 | +n:: self_insert_command() 564 | +m:: self_insert_command() 565 | +,:: self_insert_command() 566 | +.:: self_insert_command() 567 | +/:: self_insert_command() 568 | 569 | +delete:: kill_region() 570 | 571 | ;; -------------- 572 | ;; plain bindings 573 | ;; -------------- 574 | #If !dummy && !ignored_frame() && !cx 575 | 576 | `:: self_insert_command() 577 | 1:: self_insert_command() 578 | 2:: self_insert_command() 579 | 3:: self_insert_command() 580 | 4:: self_insert_command() 581 | 5:: self_insert_command() 582 | 6:: self_insert_command() 583 | 7:: self_insert_command() 584 | 8:: self_insert_command() 585 | 9:: self_insert_command() 586 | 0:: self_insert_command() 587 | -:: self_insert_command() 588 | =:: self_insert_command() 589 | q:: self_insert_command() 590 | w:: self_insert_command() 591 | e:: self_insert_command() 592 | r:: self_insert_command() 593 | t:: self_insert_command() 594 | y:: self_insert_command() 595 | u:: self_insert_command() 596 | i:: self_insert_command() 597 | o:: self_insert_command() 598 | p:: self_insert_command() 599 | [:: self_insert_command() 600 | ]:: self_insert_command() 601 | a:: self_insert_command() 602 | s:: self_insert_command() 603 | d:: self_insert_command() 604 | f:: self_insert_command() 605 | g:: self_insert_command() 606 | h:: self_insert_command() 607 | j:: self_insert_command() 608 | k:: self_insert_command() 609 | l:: self_insert_command() 610 | `;:: self_insert_command() 611 | ':: self_insert_command() 612 | \:: self_insert_command() 613 | z:: self_insert_command() 614 | x:: self_insert_command() 615 | c:: self_insert_command() 616 | v:: self_insert_command() 617 | b:: self_insert_command() 618 | n:: self_insert_command() 619 | m:: self_insert_command() 620 | ,:: self_insert_command() 621 | .:: self_insert_command() 622 | /:: self_insert_command() 623 | 624 | ;; ------------- 625 | ;; mouse buttons 626 | ;; ------------- 627 | #If !dummy && !ignored_frame() && !cx 628 | 629 | ;; plain 630 | lbutton:: mouse_event_command() 631 | rbutton:: mouse_event_command() 632 | mbutton:: mouse_event_command() 633 | xbutton1:: mouse_event_command() 634 | xbutton2:: mouse_event_command() 635 | lbutton up:: mouse_event_command() 636 | rbutton up:: mouse_event_command() 637 | mbutton up:: mouse_event_command() 638 | xbutton1 up:: mouse_event_command() 639 | xbutton2 up:: mouse_event_command() 640 | 641 | ;; ctrl 642 | ^lbutton:: mouse_event_command() 643 | ^rbutton:: mouse_event_command() 644 | ^mbutton:: mouse_event_command() 645 | ^xbutton1:: mouse_event_command() 646 | ^xbutton2:: mouse_event_command() 647 | ^lbutton up:: mouse_event_command() 648 | ^rbutton up:: mouse_event_command() 649 | ^mbutton up:: mouse_event_command() 650 | ^xbutton1 up:: mouse_event_command() 651 | ^xbutton2 up:: mouse_event_command() 652 | 653 | ;; meta 654 | !lbutton:: mouse_event_command() 655 | !rbutton:: mouse_event_command() 656 | !mbutton:: mouse_event_command() 657 | !xbutton1:: mouse_event_command() 658 | !xbutton2:: mouse_event_command() 659 | !lbutton up:: mouse_event_command() 660 | !rbutton up:: mouse_event_command() 661 | !mbutton up:: mouse_event_command() 662 | !xbutton1 up:: mouse_event_command() 663 | !xbutton2 up:: mouse_event_command() 664 | 665 | ;; shift 666 | +lbutton:: mouse_event_command() 667 | +rbutton:: mouse_event_command() 668 | +mbutton:: mouse_event_command() 669 | +xbutton1:: mouse_event_command() 670 | +xbutton2:: mouse_event_command() 671 | +lbutton up:: mouse_event_command() 672 | +rbutton up:: mouse_event_command() 673 | +mbutton up:: mouse_event_command() 674 | +xbutton1 up:: mouse_event_command() 675 | +xbutton2 up:: mouse_event_command() 676 | 677 | ;; ------------ 678 | ;; special keys 679 | ;; ------------ 680 | #If !dummy && !ignored_frame() && !cx 681 | 682 | space:: self_send_command() 683 | 684 | tab:: indent_for_tab_command() 685 | enter:: newline() 686 | escape:: keyboard_quit() 687 | backspace:: delete_backward_char() 688 | delete:: delete_char() 689 | 690 | home:: move_beginning_of_line() 691 | end:: move_end_of_line() 692 | pgup:: scroll_up() 693 | pgdn:: scroll_down() 694 | up:: previous_line() 695 | down:: next_line() 696 | left:: backward_char() 697 | right:: forward_char() 698 | 699 | insert:: overwrite_mode() 700 | 701 | scrolllock:: self_send_command() 702 | capslock:: self_send_command() 703 | numlock:: self_send_command() 704 | appskey:: self_send_command() 705 | printscreen:: self_send_command() 706 | ctrlbreak:: self_send_command() 707 | pause:: self_send_command() 708 | break:: self_send_command() 709 | help:: self_send_command() 710 | sleep:: self_send_command() 711 | 712 | ;; ------------- 713 | ;; function keys 714 | ;; ------------- 715 | #If !dummy && !ignored_frame() && !cx 716 | 717 | f1:: help() 718 | f2:: self_send_command() 719 | f3:: kmacro_start_macro() ; kmacro-start-macro-or-insert-counter 720 | f4:: kmacro_end_or_call_macro() 721 | f5:: self_send_command() 722 | f6:: self_send_command() 723 | f7:: self_send_command() 724 | f8:: self_send_command() 725 | f9:: self_send_command() 726 | f10:: self_send_command() 727 | f11:: self_send_command() 728 | f12:: self_send_command() 729 | f13:: self_send_command() 730 | f14:: self_send_command() 731 | f15:: self_send_command() 732 | f16:: kill_ring_save() ; clipboard-kill-ring-save 733 | f17:: yank() ; clipboard-yank 734 | f18:: self_send_command() 735 | f19:: self_send_command() 736 | f20:: kill_region() ; clipboard-kill-region 737 | f21:: self_send_command() 738 | f22:: self_send_command() 739 | f23:: self_send_command() 740 | f24:: self_send_command() 741 | 742 | ;; ----------- 743 | ;; numpad keys 744 | ;; ----------- 745 | #If !dummy && !ignored_frame() && !cx 746 | 747 | numpad0:: self_send_command() 748 | numpad1:: self_send_command() 749 | numpad2:: self_send_command() 750 | numpad3:: self_send_command() 751 | numpad4:: self_send_command() 752 | numpad5:: self_send_command() 753 | numpad6:: self_send_command() 754 | numpad7:: self_send_command() 755 | numpad8:: self_send_command() 756 | numpad9:: self_send_command() 757 | numpadins:: self_send_command() 758 | numpadend:: self_send_command() 759 | numpaddown:: self_send_command() 760 | numpadpgdn:: self_send_command() 761 | numpadleft:: self_send_command() 762 | numpadclear:: self_send_command() 763 | numpadright:: self_send_command() 764 | numpadhome:: self_send_command() 765 | numpadup:: self_send_command() 766 | numpadpgup:: self_send_command() 767 | numpaddot:: self_send_command() 768 | numpaddel:: self_send_command() 769 | numpaddiv:: self_send_command() 770 | numpadmult:: self_send_command() 771 | numpadadd:: self_send_command() 772 | numpadsub:: self_send_command() 773 | numpadenter:: self_send_command() 774 | -------------------------------------------------------------------------------- /prefix.ahk: -------------------------------------------------------------------------------- 1 | ;; This script provides: mark, prefix C-x, prefix argument 2 | 3 | ;; 4 | 5 | ;; - cx ... true if C-x is prefixed 6 | ;; - mark ... true if mark is active 7 | ;; - arg ... digit argument as an integer 8 | 9 | ;; 10 | 11 | ;; - set_cx()/reset_cx() 12 | ;; - set_mark()/reset_mark() 13 | ;; - set_digit_argument(n) 14 | 15 | prefix_tt := alloc_tt() 16 | mark_tt := alloc_tt() 17 | 18 | ;; -------------- 19 | ;; set/reset mark 20 | ;; -------------- 21 | 22 | mark = 0 23 | 24 | set_mark() 25 | { Global 26 | mark := 1 27 | ToolTip, mark, 45, 0, %mark_tt% 28 | } 29 | 30 | reset_mark() 31 | { Global 32 | mark := 0 33 | ToolTip, , , , %mark_tt% 34 | } 35 | 36 | add_hook("after_change_hook", "reset_mark") 37 | add_hook("after_display_transition_hook", "reset_mark") 38 | 39 | ;; ---------- 40 | ;; prefix C-x 41 | ;; ---------- 42 | 43 | cx = 0 44 | 45 | set_cx() 46 | { Global 47 | cx := 1 48 | ToolTip, C-x -, 1, 0, %prefix_tt% 49 | } 50 | 51 | reset_cx() 52 | { Global 53 | cx := 0 54 | ToolTip, , , , %prefix_tt% 55 | } 56 | 57 | add_hook("pre_command_hook", "reset_cx") 58 | 59 | ;; -------------- 60 | ;; digit argument 61 | ;; -------------- 62 | 63 | arg = 0 64 | arg_internal = 0 65 | 66 | set_digit_argument(n) 67 | { Global 68 | arg_internal := n 69 | ToolTip, %arg_internal%, 1, 0, %prefix_tt% 70 | } 71 | 72 | ;; retrive arg from arg_internal 73 | get_argument() 74 | { Global 75 | arg := arg_internal 76 | arg_internal = 0 77 | ToolTip, , , , %prefix_tt% 78 | } 79 | 80 | add_hook("pre_command_hook", "get_argument") 81 | --------------------------------------------------------------------------------