|Version 1 (modified by rme, 6 years ago)|
13 Simple Customization
Hemlock can be customized and extended to a very large degree, but in order to do much of this a knowledge of Lisp is required. These advanced aspects of customization are discussed in the Hemlock Command Implementor's Manual, while simpler methods of customization are discussed here.
13.1 Keyboard Macros
Keyboard macros provide a facility to turn a sequence of commands into one command.
Define Keyboard Macro (bound to C-x () [Command]
End Keyboard Macro (bound to C-x )) [Command]
Define Keyboard Macro starts the definition of a keyboard macro. The commands which are invoked up until End Keyboard Macro is invoked become the definition for the keyboard macro, thus replaying the keyboard macro is synonymous with invoking that sequence of commands.
Last Keyboard Macro (bound to C-x e) [Command]
This command is the keyboard macro most recently defined; invoking it will replay the keyboard macro. The prefix argument is used as a repeat count.
Define Keyboard Macro Key (bound to C-x M-(; ) [Command]
Define Keyboard Macro Key Confirm (initial value t) [Variable]
This command prompts for a key before going into a mode for defining keyboard macros. After defining the macro Hemlock binds it to the key. If the key is already bound, Hemlock asks for confirmation before clobbering the binding; this prompting can be inhibited by setting Define Keyboard Macro Key Confirm to nil.
Keyboard Macro Query (bound to C-x q) [Command]
This command conditionalizes the execution of a keyboard macro. When invoked during the definition of a macro, it does nothing. When the macro replays, it prompts the user for a key-event indicating what action to take. The following commands are defined:
- Exit all repetitions of this keyboard macro. More than one may have been specified using a prefix argument.
- Space, y
- Proceed with the execution of the keyboard macro.
- Delete, Backspace, n
- Skip the remainder of the keyboard macro and go on to the next repetition, if any.
- Do all remaining repetitions of the keyboard macro without prompting.
- Complete this repetition of the macro and then exit without doing any of the remaining repetitions.
- Do a recursive edit and then prompt again.
Name Keyboard Macro [Command]
This command prompts for the name of a command and then makes the definition for that command the same as Last Keyboard Macro's current definition. The command which results is not clobbered when another keyboard macro is defined, so it is possible to keep several keyboard macros around at once. The resulting command may also be bound to a key using Bind Key, in the same way any other command is.
Many keyboard macros are not for customization, but rather for one-shot use, a typical example being performing some operation on each line of a file. To add "del " to the beginning and ".*" to the end of every line in in a buffer, one could do this:
C-x ( d e l Space C-e . * C-n C-a C-x ) C-u 9 9 9 C-x e
First a keyboard macro is defined which performs the desired operation on one line, and then the keyboard macro is invoked with a large prefix argument. The keyboard macro will not actually execute that many times; when the end of the buffer is reached the C-n will get an error and abort the execution.
13.2 Binding Keys
Bind Key [Command]
This command prompts for a command, a key and a kind of binding to make, and then makes the specified binding. The following kinds of bindings are allowed:
- Prompts for a buffer and then makes a key binding which is only present when that buffer is the current buffer.
- Prompts for the name of a mode and then makes a key binding which is only in present when that mode is active in the current buffer.
- Makes a global key binding which is in effect when there is no applicable mode or buffer key binding. This is the default.
Delete Key Binding [Command]
This command prompts for a key binding the same way that Bind Key does and makes the specified binding go away.
13.3 Hemlock Variables
A number of commands use Hemlock variables as flags to control their behavior. Often you can get a command to do what you want by setting a variable. Generally the default value for a variable is chosen to be the safest value for novice users.
Set Variable [Command]
This command prompts for the name of a Hemlock variable and an expression, then sets the current value of the variable to the result of the evaluation of the expression.
Like Set Variable, this command prompts for the name of a Hemlock variable and an expression. Like Bind Key, this command prompts for a place: mode, buffer or local. The result of evaluating the expression is defined to be the value of the named variable in the specified place.
This command is most useful for making mode or buffer local bindings of variables. Redefining a variable in a mode or buffer will create a customization that takes effect only when in that mode or buffer.
Unlike Set Variable, the variable name need not be the name of an existing variable: new variables may be defined. If the variable is already defined in the current environment, Hemlock copies the documentation and hooks to the new definition.
13.4 Init Files
Hemlock customizations are normally put in Hemlock's initialization file, "hemlock-init.lisp", or when compiled "hemlock-init.fasl". When starting up Lisp, use the -hinit switch to indicate a particular file. The contents of the init file must be Lisp code, but there is a fairly straightforward correspondence between the basic customization commands and the equivalent Lisp code. Rather than describe these functions in depth here, a brief example follows:
;;; -*- Mode: Lisp; Package: Hemlock -*- ;;; It is necessary to specify that the customizations go in ;;; the hemlock package. (in-package 'hemlock) ;;; Bind Kill Previous Word to M-h. (bind-key "Kill Previous Word" '#(#\m-h)) ;;; ;;; Bind Extract List to C-M-? when in Lisp mode. (bind-key "Extract List" '#(#\c-m-?) :mode "Lisp") ;;; Make C-w globally unbound. (delete-key-binding '#(#\c-w)) ;;; Make string searches case-sensitive. (setv string-search-ignore-case nil) ;;; ;;; Make "Query Replace" replace strings literally. (setv case-replace nil)
For a detailed description of these functions, see the Hemlock Command Implementor's Manual.