Désactiver le remplissage automatique en mode local (ou un fill-paragraph) avec emacs
Question
J'utilise M-q pour le remplissage paragraphe, je peux faire le non-fill-paragraph en auto-fill-mode?
En mode org, je parfois entrer [[Très long HTML] [Nom avec des espaces]] , et pour le « nom avec des espaces » le mode de remplissage automatique briser toute la ligne en fonction de la inséré l'espace, ce qui le rend très laid.
Y at-il une commande quelque chose comme un-fill-paragraph? Ou, est-il un moyen de désactiver le remplissage automatique en mode temporairement / localement?
La solution
Emacs n'enregistre pas ce qui était votre ligne avant d'appeler fill-paragraph
. La seule chose que vous pouvez faire est C -_ qui exécute la commande undo. Il peut annuler votre commande fill-paragraph
mais seulement si elle est l'appel de commande précédent.
Si vous voulez mettre un paragraphe à plusieurs lignes sur une ligne que vous pourriez faire comme ceci:
- Sélectionnez la région
- CM -% Cq Cj RET ESPACE RET
Autres conseils
Xah Lee a mis à jour son code depuis la réponse de monotux, et je refondus quelque peu pour une meilleure lisibilité:
(defun my-toggle-fill-paragraph ()
;; Based on http://xahlee.org/emacs/modernization_fill-paragraph.html
"Fill or unfill the current paragraph, depending upon the current line length.
When there is a text selection, act on the region.
See `fill-paragraph' and `fill-region'."
(interactive)
;; We set a property 'currently-filled-p on this command's symbol
;; (i.e. on 'my-toggle-fill-paragraph), thus avoiding the need to
;; create a variable for remembering the current fill state.
(save-excursion
(let* ((deactivate-mark nil)
(line-length (- (line-end-position) (line-beginning-position)))
(currently-filled (if (eq last-command this-command)
(get this-command 'currently-filled-p)
(< line-length fill-column)))
(fill-column (if currently-filled
most-positive-fixnum
fill-column)))
(if (region-active-p)
(fill-region (region-beginning) (region-end))
(fill-paragraph))
(put this-command 'currently-filled-p (not currently-filled)))))
Pour refaire une longue ligne d'un paragraphe en mode Org, je me suis donné une nouvelle commande. Voici le code associé Lisp:
(defun fp-unfill-paragraph (&optional justify region)
(interactive (progn
(barf-if-buffer-read-only)
(list (if current-prefix-arg 'full) t)))
(interactive)
(let ((fill-column 100000))
(fill-paragraph justify region)))
(global-set-key "\C-ceu" 'fp-unfill-paragraph)
Bien sûr, vous réglez la commande raccourci clavier comme bon vous semble!
J'utilise l'extrait ci-dessous pour remplir et les paragraphes non remplissage (en utilisant seulement M-q
), il est vraiment, vraiment à portée de main. Je l'ai emprunté à partir Xah Lee, mais enlevé quelques espaces et commentaires afin de l'adapter ici. Le lien dans le premier commentaire va à son code d'origine.
;; http://xahlee.org/emacs/modernization_fill-paragraph.html
(defun compact-uncompact-block ()
"Remove or add line endings on the current block of text.
This is similar to a toggle for fill-paragraph and unfill-paragraph
When there is a text selection, act on the region.
When in text mode, a paragraph is considered a block. When in programing
language mode, the block defined by between empty lines.
Todo: The programing language behavior is currently not done.
Right now, the code uses fill* functions, so does not work or work well
in programing lang modes. A proper implementation to compact is replacing
newline chars by space when the newline char is not inside string.
"
(interactive)
(let (bds currentLineCharCount currentStateIsCompact
(bigFillColumnVal 4333999) (deactivate-mark nil))
(save-excursion
(setq currentLineCharCount
(progn
(setq bds (bounds-of-thing-at-point 'line))
(length (buffer-substring-no-properties (car bds) (cdr bds)))))
(setq currentStateIsCompact
(if (eq last-command this-command)
(get this-command 'stateIsCompact-p)
(if (> currentLineCharCount fill-column) t nil)))
(if (and transient-mark-mode mark-active)
(if currentStateIsCompact
(fill-region (region-beginning) (region-end))
(let ((fill-column bigFillColumnVal))
(fill-region (region-beginning) (region-end)))
)
(if currentStateIsCompact
(fill-paragraph nil)
(let ((fill-column bigFillColumnVal))
(fill-paragraph nil))))
(put this-command 'stateIsCompact-p
(if currentStateIsCompact
nil t)))))
(global-set-key (kbd "M-q") 'compact-uncompact-block)