Difference between revisions of "Abbrevs"
(Created page with " Abbbrevs are small pieces of text that are expanded as you type. The expansion is context sensitive, so it depends on the mode you opened the file: if you open a .py file...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | = Abbrevs = | ||
Abbbrevs are small pieces of text that are expanded as you type. | Abbbrevs are small pieces of text that are expanded as you type. | ||
The expansion is context sensitive, so it depends on the mode you opened | The expansion is context sensitive, so it depends on the mode you opened | ||
− | the file: if you open a .py file, it is python-mode so it uses the table | + | the file: |
− | for python | + | |
− | for C language | + | * if you open a .py file, it is python-mode so it uses the table for python |
+ | * if you open a .c file, it is C language so it uses de table for C language | ||
+ | * so on | ||
Abbrevs are loaded from a Emacs-LISP file. The traditional location of | Abbrevs are loaded from a Emacs-LISP file. The traditional location of | ||
Line 14: | Line 17: | ||
The format of the sections in this file is the following: | The format of the sections in this file is the following: | ||
− | + | <nowiki> | |
− | (define-abbrev-table 'xxxx-mode-abbrev-table '( | + | (define-abbrev-table 'xxxx-mode-abbrev-table '( |
− | + | ("abbr" "text to expand for abbr" nil 0) | |
− | + | ("other" "other text" nil 0) | |
− | + | ... | |
− | + | ))</nowiki> | |
Example: | Example: | ||
− | + | <nowiki> | |
− | (define-abbrev-table 'html-mode-abbrev-table '( | + | (define-abbrev-table 'html-mode-abbrev-table '( |
− | + | ("htmls" "<html>\n<head>\n<title></title>\n<style></style>\n</head>\n<body>\n</body>\n</html>\n" nil 0) | |
− | + | ("table" "<table>\n</table>" nil 0) | |
− | + | ("tr" "<tr><td></td></tr>" nil 0) | |
− | + | ("td" "<td> </td>") | |
− | + | ... other usefull and frequently used HTML definitions here ... | |
− | + | ))</nowiki> | |
Abbrev files can be read using this Emacs Lisp call: | Abbrev files can be read using this Emacs Lisp call: | ||
− | (read-abbrev-file "~/.abbrev_defs") | + | (read-abbrev-file "~/.abbrev_defs") |
You can use it dynamically as a Emacs command: | You can use it dynamically as a Emacs command: | ||
− | M-x read-abbrev-file | + | M-x read-abbrev-file |
There is a minor mode of Emacs called Abbrev-mode. It can be | There is a minor mode of Emacs called Abbrev-mode. It can be | ||
switched on an off with this command: | switched on an off with this command: | ||
− | M-x abbrev-mode | + | M-x abbrev-mode |
If you (as me, rcaguiar) don't like very much this mode, you can | If you (as me, rcaguiar) don't like very much this mode, you can | ||
disable it in .emacs file adding the following line: | disable it in .emacs file adding the following line: | ||
− | (setq default-abbrev-mode -1) | + | (setq default-abbrev-mode -1) |
At the end of Emacs session it usually writes the current Abbrevs to | At the end of Emacs session it usually writes the current Abbrevs to | ||
Line 53: | Line 56: | ||
.emacs file: | .emacs file: | ||
− | (setq save-abbrevs nil) | + | (setq save-abbrevs nil) |
− | To make the use of Abbrevs less invasive | + | To make the use of Abbrevs less invasive than Abbrev Mode, you can use the |
Emacs Lisp function "expand-abbrevs". It is usually bound to some shortcut | Emacs Lisp function "expand-abbrevs". It is usually bound to some shortcut | ||
as < C-x ' > for instance. You can use < C-h b > to confer the bindings. To | as < C-x ' > for instance. You can use < C-h b > to confer the bindings. To | ||
Line 61: | Line 64: | ||
.emacs file: | .emacs file: | ||
− | (global-set-key [f4] 'expand-abbrev) | + | (global-set-key [f4] 'expand-abbrev) |
Latest revision as of 21:36, 11 August 2015
Abbrevs
Abbbrevs are small pieces of text that are expanded as you type.
The expansion is context sensitive, so it depends on the mode you opened the file:
- if you open a .py file, it is python-mode so it uses the table for python
- if you open a .c file, it is C language so it uses de table for C language
- so on
Abbrevs are loaded from a Emacs-LISP file. The traditional location of this file is:
~/.abbrev_defs
The format of the sections in this file is the following:
(define-abbrev-table 'xxxx-mode-abbrev-table '( ("abbr" "text to expand for abbr" nil 0) ("other" "other text" nil 0) ... ))
Example:
(define-abbrev-table 'html-mode-abbrev-table '( ("htmls" "<html>\n<head>\n<title></title>\n<style></style>\n</head>\n<body>\n</body>\n</html>\n" nil 0) ("table" "<table>\n</table>" nil 0) ("tr" "<tr><td></td></tr>" nil 0) ("td" "<td> </td>") ... other usefull and frequently used HTML definitions here ... ))
Abbrev files can be read using this Emacs Lisp call:
(read-abbrev-file "~/.abbrev_defs")
You can use it dynamically as a Emacs command:
M-x read-abbrev-file
There is a minor mode of Emacs called Abbrev-mode. It can be switched on an off with this command:
M-x abbrev-mode
If you (as me, rcaguiar) don't like very much this mode, you can disable it in .emacs file adding the following line:
(setq default-abbrev-mode -1)
At the end of Emacs session it usually writes the current Abbrevs to file. For it to NOT happen, you need to include the following line in .emacs file:
(setq save-abbrevs nil)
To make the use of Abbrevs less invasive than Abbrev Mode, you can use the Emacs Lisp function "expand-abbrevs". It is usually bound to some shortcut as < C-x ' > for instance. You can use < C-h b > to confer the bindings. To bind it to some other key combination you can use the following line in your .emacs file:
(global-set-key [f4] 'expand-abbrev)