Цифровой садик - приветственная

Цифровой садик - приветственная | Полный список всего, что тут есть | RSS | Подписаться через follow.it

19.04.2022

темплейты и шаблоны

Приятная возможность ускорить и упростить себе набор каких-то повторяющихся стандартных штук. Шаблонные тексты, разметка, да мало ли. Заодно снижается вероятность ошибиться в них.

abbrev

Внезапно обнаружила, что abbrev-ы у меня раскрываются только при использовании abbrev-prefix-mark (M-'). Это лучше, чем если б вообще никак. Но огорчает. Причём проблема не в моём конфиге, потому что при запуске с -Q эффект сохраняется. 2021-10-06 04:31:26

На 2022-01-24 M-' требуется только для аббревов с кириллицей.

как сохранила некогда

Обычно сокращения просто набирают в тексте, а потом после них оказывается пробел или знак препинания и сокращение само раскрывается. Любой символ, которому "не полагается" быть частью слова, раскрывает сокращение. Любой символ, который "может" входить в состав слова, может быть частью сокращения.

You may wish to expand an abbrev and attach a prefix to the expansion; for example, if ‘cnst’ expands into ‘construction’, you might want to use it to enter ‘reconstruction’. It does not work to type recnst, because that is not necessarily a defined abbrev. What you can do is use the command M-' (abbrev-prefix-mark) in between the prefix ‘re’ and the abbrev ‘cnst’. First, insert ‘re’. Then type M-'; this inserts a hyphen in the buffer to indicate that it has done its work. Then insert the abbrev ‘cnst’; the buffer now contains ‘re-cnst’. Now insert a non-word character to expand the abbrev ‘cnst’ into ‘construction’. This expansion step also deletes the hyphen that indicated M-' had been used. The result is the desired ‘reconstruction’.

If you actually want the text of the abbrev in the buffer, rather than its expansion, you can accomplish this by inserting the following punctuation with C-q. Thus, foo C-q , leaves ‘foo,’ in the buffer, not expanding it.

If you expand an abbrev by mistake, you can undo the expansion and bring back the abbrev itself by typing C-_ to undo (see Undo). This also undoes the insertion of the non-word character that expanded the abbrev.

M-x expand-region-abbrevs searches through the region for defined abbrevs, and for each one found offers to replace it with its expansion. This command is useful if you have typed in text using abbrevs but forgot to turn on Abbrev mode first. It may also be useful together with a special set of abbrev definitions for making several global replacements at once. This command is effective even if Abbrev mode is not enabled.

  • Activate the abbrev minor-mode in org-mode:
    • M-x abbrev-mode
    • Permanently:
      • (add-hook 'org-mode-hook (lambda () (abbrev-mode 1)))
  • In org-mode, type "sbp" (a sample abbreviation for a perl source block).
  • Immediately after "sbp" type C-x a i l.
  • Enter the expansion:
    • #+begin_src perl[C-q C-j][C-q C-j]#+end_src
    • Note: C-q C-j creates a new line in the minibuffer
  • Now, whenever, you type sbp followed by SPACE or RET in an org-mode buffer, the src block will magically appear.
  • To review your list of abbrevs, type M-x edit-abbrevs.

Ещё способ правки сокращений.

The output from M-x list-abbrevs looks like this:

     various other tables...
     (lisp-mode-abbrev-table)
     "dk"              0    "define-key"
     (global-abbrev-table)
     "dfn"             0    "definition"

(Some blank lines of no semantic significance, and some other abbrev tables, have been omitted.)

A line containing a name in parentheses is the header for abbrevs in a particular abbrev table; global-abbrev-table contains all the global abbrevs, and the other abbrev tables that are named after major modes contain the mode-specific abbrevs.

Within each abbrev table, each nonblank line defines one abbrev. The word at the beginning of the line is the abbrev. The number that follows is the number of times the abbrev has been expanded. Emacs keeps track of this to help you see which abbrevs you actually use, so that you can eliminate those that you don't use often. The string at the end of the line is the expansion.

Some abbrevs are marked with ‘(sys)’. These “system” abbrevs (see Abbrevs) are pre-defined by various modes, and are not saved to your abbrev file. To disable a “system” abbrev, define an abbrev of the same name that expands to itself, and save it to your abbrev file.

M-x edit-abbrevs allows you to add, change or kill abbrev definitions by editing a list of them in an Emacs buffer. The list has the same format described above. The buffer of abbrevs is called ‘*Abbrevs*’, and is in Edit-Abbrevs mode. Type C-c C-c in this buffer to install the abbrev definitions as specified in the buffer—and delete any abbrev definitions not listed.

The command edit-abbrevs is actually the same as list-abbrevs except that it selects the buffer ‘*Abbrevs*’ whereas list-abbrevs merely displays it in another window.

Быстрокнопки

C-x a g
Define an abbrev, using one or more words before point as its expansion (add-global-abbrev).
C-x a l
Similar, but define an abbrev specific to the current major mode (add-mode-abbrev).
C-x a i g
Define a word in the buffer as an abbrev (inverse-add-global-abbrev).
C-x a i l
Define a word in the buffer as a mode-specific abbrev (inverse-add-mode-abbrev).
M-x define-global-abbrev <RET> abbrev <RET> exp <RET>
Define abbrev as an abbrev expanding into exp.
M-x define-mode-abbrev <RET> abbrev <RET> exp <RET>
Define abbrev as a mode-specific abbrev expanding into exp.
M-x kill-all-abbrevs

Discard all abbrev definitions, leaving a blank slate.

The usual way to define an abbrev is to enter the text you want the abbrev to expand to, position point after it, and type C-x a g (add-global-abbrev). This reads the abbrev itself using the minibuffer, and then defines it as an abbrev for one or more words before point. Use a numeric argument to say how many words before point should be taken as the expansion. For example, to define the abbrev ‘foo’ as mentioned above, insert the text ‘find outer otter’ and then type C-u 3 C-x a g f o o <RET>.

An argument of zero to C-x a g means to use the contents of the region as the expansion of the abbrev being defined.

The command C-x a l (add-mode-abbrev) is similar, but defines a mode-specific abbrev. Mode-specific abbrevs are active only in a particular major mode. C-x a l defines an abbrev for the major mode in effect at the time C-x a l is typed. The arguments work the same as for C-x a g.

If the abbrev text itself is already in the buffer, you can use the commands C-x a i g (inverse-add-global-abbrev) and C-x a i l (inverse-add-mode-abbrev) to define it as an abbrev by specify the expansion in the minibuffer. These commands are called “inverse” because they invert the meaning of the two text strings they use (one from the buffer and one read with the minibuffer).

You can define an abbrev without inserting either the abbrev or its expansion in the buffer using the command define-global-abbrev. It reads two arguments—the abbrev, and its expansion. The command define-mode-abbrev does likewise for a mode-specific abbrev.

To change the definition of an abbrev, just define a new definition. When the abbrev has a prior definition, the abbrev definition commands ask for confirmation before replacing it.

To remove an abbrev definition, give a negative argument to the abbrev definition command: C-u - C-x a g or C-u - C-x a l. The former removes a global definition, while the latter removes a mode-specific definition. M-x kill-all-abbrevs removes all abbrev definitions, both global and local.

Saving Abbrevs

These commands allow you to keep abbrev definitions between editing sessions.

M-x write-abbrev-file <RET> file <RET>
Write a file file describing all defined abbrevs.
M-x read-abbrev-file <RET> file <RET>
Read the file file and define abbrevs as specified therein.
M-x quietly-read-abbrev-file <RET> file <RET>
Similar but do not display a message about what is going on.
M-x define-abbrevs
Define abbrevs from definitions in current buffer.
M-x insert-abbrevs

Insert all abbrevs and their expansions into current buffer.

M-x write-abbrev-file reads a file name using the minibuffer and then writes a description of all current abbrev definitions into that file. This is used to save abbrev definitions for use in a later session. The text stored in the file is a series of Lisp expressions that, when executed, define the same abbrevs that you currently have.

M-x read-abbrev-file reads a file name using the minibuffer and then reads the file, defining abbrevs according to the contents of the file. The function quietly-read-abbrev-file is similar except that it does not display a message in the echo area; you cannot invoke it interactively, and it is used primarily in your init file (see Init File). If either of these functions is called with nil as the argument, it uses the file given by the variable abbrev-file-name, which is ~/.emacs.d/abbrev_defs by default. This is your standard abbrev definition file, and Emacs loads abbrevs from it automatically when it starts up. (As an exception, Emacs does not load the abbrev file when it is started in batch mode. See Initial Options, for a description of batch mode.)

Emacs will offer to save abbrevs automatically if you have changed any of them, whenever it offers to save all files (for C-x s or C-x C-c). It saves them in the file specified by abbrev-file-name. This feature can be inhibited by setting the variable save-abbrevs to nil.

The commands M-x insert-abbrevs and M-x define-abbrevs are similar to the previous commands but work on text in an Emacs buffer. M-x insert-abbrevs inserts text into the current buffer after point, describing all current abbrev definitions; M-x define-abbrevs parses the entire current buffer and defines abbrevs accordingly.

Прочее

  • Есть auto-insert, используется при создании новых файлов.
  • Есть «вообще» yasnippet, популярная штука, но мне не понравилось.

Если у вас есть мысли, комментарии, предложения или отклики по поводу этой страницы или этого цифрового сада в целом, напишите мне сообщение через Яндекс.Форму или на agnessa@agnessa.pp.ru. Мне ооочень интересно!

Задонатить.


An IndieWeb Webring 🕸💍