Se você prefixar uma função com C-h f , poderá ler a documentação para ela. Se você fizer isso por fill-region , ele mostrará, entre outras coisas:
The 'fill-column' variable controls the width.
E se você verificar o manual do Emacs nos comandos de preenchimento , pode ler:
The maximum line width for filling is specified by the buffer-local variable
fill-column. The default value (see Locals) is 70. The easiest way to setfill-columnin the current buffer is to use the commandC-x f(set-fill-column). With a numeric argument, it uses that as the new fill column. With justC-uas argument, it setsfill-columnto the current horizontal position of point.
Isso explica como C-u 70 M-x fill-region funciona. Também mostra que a largura a ser preenchida pode ser definida via C-x f . Assim, pode não ser necessário escrever uma função que solicite um parâmetro, ou seja, você pode usar C-x f e fill-region .
Se você ainda quiser novas funções para fazer isso, use o seguinte:
(defun fill-region-ask-width (fill-width)
"Asks for a width and fills the region to it"
(interactive "nFill region to column: ")
(fill-region-width fill-width))
(defun fill-region-width-70 ()
"Fills the region with width 70"
(interactive)
(fill-region-width 70))
(defun fill-region-width (fill-width)
"Fills the region with the given width"
(set-fill-column fill-width)
(fill-region (region-beginning) (region-end)))
As funções são explicadas por suas strings de doc , mas aqui estão mais algumas notas:
-
fill-region-ask-widthrecebe um argumento, perguntando ao usuário e trata esse número como um inteiro (n) e passa parafill-region-prompt-width. -
fill-region-width-70tem apenas um número codificado que passa parafill-region-prompt-width. -
fill-region-widthé uma função auxiliar para modularizar o que as outras duas funções têm em comum. Não é definido como interativo, por isso não é possível chamar viaM-x. Definefill-columnpara o argumento fornecido e preenche a região '.
Para aprender como escrever funções do Emacs e ligá-las a chaves, consulte Aprenda Elisp para o Emacs: Lição 4-2 - Adicionando Funções Personalizadas ao Emacs .