Jetzt suchen:
  Home o MicroEmacs o Macros




Autocompletion macro

Aim: if you are writing a document, or a program you are writing the same words again and again. Often if you are a programmer you have to remember the name of a certain function you just were creating. In my cases most of compiler-error-messages are coming from misspelled function or variable names. To minimise such trouble you can use the following macro. Start writing the word the first two, three, four or five letters and execute the macro, it will search backward for these letters and fill the word with the first possible word it was founding. So these letters should match the proper word beginning correctly. This is especially useful if you see the other word still on the screen. Normally you would thy the function or macro-name: what-for-a-wonderful-macro again, or you try to copy and past it, very borrowing. I simple write "what-" and press "C-1" and the name is completed: what-for-a-wonderful-macro.
define-macro autocomplete-word 
    ; remember position 
    set-alpha-mark "t" 
    ; copy clip to variable 
    set-variable #l0 @y 
    ; how many letters ? 
    set-variable #l1 &len #l0 
    ; empty clipboard 
    -1 yank 
    ; search clip and extract rest of the word 
    search-backward #l0 
    #l1 forward-char 
    goto-alpha-mark "t" 
    -1 yank 
global-bind-key "autocomplete-word" "C-1" 

Repeat the previous line

The following macro works well together with the previos one. It repeats the previous line, beginning from the actual cursor button. This helps if you have to rewrite almost the same code in the next line just replacing a small amount of letters. Imagine you have to write the following java-code:

// java example code 
Button b1 = new Button("Red"); new 
Button b2 = new Button("Green"); 
Button b3 = new Button("Blue"); 

Much of this code is redundant. So with the aid of the previous an the following macro you can save time:

define-macro repeat-line 
    -1 yank 
global-bind-key "repeat-line" "C-2" 

Concerning the JAVA-example you simple write the following:

 Button b1 = new Button("Red");
 B(C-1) b2(C-2)(C-left) 
 and you rewrite the name of the second button.


imenu.emf is an macro simliar to the emacs imenu. You must add the line:

 define-macro-file imenu imenu
define-macro-file imenu imenu-refresh
to your user.emf-file and put imenu.emf into your user directory in order to invoke imenu. If you want to redefine the indexing schema you must invoke imenu-refresh.

An imenu of imenu.emf


One of the things I need often during programming is a call to perldoc or man to read some documentation. You can nicely view manpages inside MicroEmacs and with the aid of perldoc.emf it is also possible to view perldoc-manpages. Save perldoc.emf and add the line
define-macro-file perldoc
to your user.emf or to your myperl.emf and you can invoke perldoc via perldoc.

MicroEmacs as a perldoc-viewer

previous o next