Alex Bennee mentions the excellent longlines-mode in a recent post. I learnt something new – that it can highlight hard returns using (longlines-show-hard-newlines)
. Thanks Alex.
What is so good about it when you can wrap a paragraph at any time using M-q (fill-paragraph)
? It wraps a paragraph in realtime as you are editing it, just like a word processor. And not only that, it uses soft newlines. If you cut and paste it, the result is not wrapped which is generally what you want.
I use longlines-mode a lot when I’m not editing source code. One thing I do is dump text in a scratch buffer (created with C-x b *random-name* <RET>
) and then I press C-c C-l
. Now I can look at two or more parts of the text at the same time using C-x 2
and related functions.
(defun set-longlines-mode () (interactive) (text-mode) (longlines-mode 1)) (global-set-key (kbd "C-c C-l") 'set-longlines-mode)
Just as Alex does, I use longlines-mode for writing my blog posts. However, I write most of my blog posts using muse so I add it to the muse-mode-hook
.
(defun muse-minor-modes () (longlines-mode 1) (font-lock-mode 0)) (add-hook 'muse-mode-hook 'muse-minor-modes)
Longlines mode is a hack which modifies the buffer to present long lines as screen lines. The mode is now pretty much superseded by Visual-line mode with real word-wrapping. I can’t find the discussion now but Emacs developers consider deprecating Longlines mode in the future. The mode probably won’t completely disappear any time soon though.
M-x customize-group RET visual-line RET
(if (fboundp ‘visual-line-mode)
(visual-line-mode 1)
(longlines-mode 1))
Hi Fz,
I had a look at visual-line-mode and I couldn’t see any way of highlighting hard returns – is that possible?
Yes. There is another minor mode for that:
M-x whitespace-newline-mode
Also, you can think backwards and show “soft newlines” aka. line continuation in fringe(s). I use this:
(setq visual-line-fringe-indicators ‘(nil right-curly-arrow))
So hard newlines are those which don’t have a curly arrow at the right fringe. It works in visual-line-mode. Of course you can use both, whitespace-newline-mode and arrow(s) in the fringe.
Cool, thanks Fz. How do you find out about these modes? Is there some documentation I’m missing, or is it browsing the wiki, or something else?
I find out about Emacs’s features by accident or maybe through Planet Emacsen or with apropos commands. When I’m looking for something specific I usually start with “C-h a” (M-x apropos-command) or just generally “M-x apropos”. If I found some interesting command or mode I usually check “M-x customize-group” to check if there is a group of user settings for that feature.
As you probably know, not every piece of Emacs is documented in Info docs. Emacs is probably too huge for that. But functions and variables document themselves so one just have to look for their own documentation. For example, if I want to check if there is a mode which is related to newlines. I could search “C-h a newline.*-mode”
Accidental discovery eh? I do a lot of that myself too š And of course I use apropos and info myself which are pretty nice but not quite as good as organised/cross referenced documentation a la php, perl and python. I hadn’t thought of customize-group though – nice tip.
I also started using visual-line-mode instead of longlines, but I do miss the wrapping of a paragraph in realtime.
Another feature I am missing is:
‘(longlines-wrap-follows-window-size t)
Is there any way to make visual-line-mode do these two things?