Discussion:
Emacs automatic line wrapping
Jason
2017-08-03 02:47:52 UTC
Permalink
I am using emacs24 for my text editor with mutt (in a terminal).
How can I set it to automatically wrap the lines at a certain number
of characters?
--
Jason
-------------------------------------------------
Your manuscript is both good and original, but the
part that is good is not original and the part that
is original is not good. -- Samuel Johnson
Ian Zimmerman
2017-08-03 03:49:30 UTC
Permalink
Post by Jason
I am using emacs24 for my text editor with mutt (in a terminal).
How can I set it to automatically wrap the lines at a certain number
of characters?
"M-x auto-fill-mode" will do it in a new buffer, provided you set your
fill-column variable. You can do the latter by adding a line to your
.emacs, or with the emacs customization feature: M-x customize-option
and follow the UI.

If you always want this on in mutt compose buffer, you need to use a
"hook". This is a complex topic beyond the scope of this forum, but
covered thoroughly in your emacs documentation.

Also, in this situation (which is also my situation), you should arrange
to open these buffers in Message mode, rather than in Fundamental mode.
To do this notice the pattern in the temporary file name (in the mode
line) and add an item to auto-mode-alist (again, look up in emacs
documentation). With this in place you'll get any number of goodies,
like highlighted headers and extra key combinations to jump to each
header and so on. In fact auto-fill-mode may be already turned on for
you.

Emacs is a huge and complex beast, but it does tons of useful things.
Too bad many people seem to not know about them.
--
Please don't Cc: me privately on mailing lists and Usenet,
if you also post the followup to the list or newsgroup.
Do obvious transformation on domain to reply privately _only_ on Usenet.
Luis Mochan
2017-08-03 17:36:21 UTC
Permalink
Post by Ian Zimmerman
Post by Jason
I am using emacs24 for my text editor with mutt (in a terminal).
How can I set it to automatically wrap the lines at a certain number
of characters?
"M-x auto-fill-mode" will do it in a new buffer, provided you set your
fill-column variable.
If you have already opened your buffer, you can wrap the lines of a paragraph with M-q.

You can set the fill column to say, 72 with C-u 7 2 C-x f

Regards,
Luis
--
o
W. Luis Mochán, | tel:(52)(777)329-1734 /<(*)
Instituto de Ciencias Físicas, UNAM | fax:(52)(777)317-5388 `>/ /\
Apdo. Postal 48-3, 62251 | (*)/\/ \
Cuernavaca, Morelos, México | ***@fis.unam.mx /\_/\__/
GPG: 791EB9EB, C949 3F81 6D9B 1191 9A16 C2DF 5F0A C52B 791E B9EB
Jason
2017-08-12 01:44:49 UTC
Permalink
Post by Luis Mochan
Post by Ian Zimmerman
Post by Jason
I am using emacs24 for my text editor with mutt (in a terminal).
How can I set it to automatically wrap the lines at a certain number
of characters?
"M-x auto-fill-mode" will do it in a new buffer, provided you set your
fill-column variable.
If you have already opened your buffer, you can wrap the lines of a paragraph with M-q.
You can set the fill column to say, 72 with C-u 7 2 C-x f
Thank you for both replies. I am new to emacs and while I know it can do many
different things, right now I would just like it to automatically wrap lines
when using for composing messages. "M-x auto-fill-mode" works in the buffer but
I would like it to startup in that mode. Here's what's in my config file:

(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(auto-fill-mode t)
'(fill-column 80)
'(fill-nobreak-predicate nil))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)

What am I missing?
Thanks.
--
Jason
Ian Zimmerman
2017-08-12 03:57:24 UTC
Permalink
Post by Jason
'(auto-fill-mode t)
What am I missing?
Thanks.
auto-fill-mode is a function (more precisely a command, or interactive
function), not a variable.

To make it automatic, you need a hook, as I said. And given that,
arranging for Message mode may actually be simpler :-P
--
Please don't Cc: me privately on mailing lists and Usenet,
if you also post the followup to the list or newsgroup.
Do obvious transformation on domain to reply privately _only_ on Usenet.
Arkadiusz Drabczyk
2017-08-12 20:37:30 UTC
Permalink
Post by Jason
Post by Luis Mochan
Post by Ian Zimmerman
Post by Jason
I am using emacs24 for my text editor with mutt (in a terminal).
How can I set it to automatically wrap the lines at a certain number
of characters?
"M-x auto-fill-mode" will do it in a new buffer, provided you set your
fill-column variable.
If you have already opened your buffer, you can wrap the lines of a paragraph with M-q.
You can set the fill column to say, 72 with C-u 7 2 C-x f
Thank you for both replies. I am new to emacs and while I know it can do many
different things, right now I would just like it to automatically wrap lines
when using for composing messages. "M-x auto-fill-mode" works in the buffer but
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(auto-fill-mode t)
'(fill-column 80)
'(fill-nobreak-predicate nil))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
What am I missing?
Thanks.
Is that your *whole* Emacs config?

As said above you need at least one hook. In order to easily use
Emacs in programs such as mutt or slrn I recommend mutt-mode. I
cannot find on the net anywhere any more so I put it here
http://drabczyk.org/mutt.el. mutt-mode will add several nice
keybindings such as C-c C-c to automatically save a message and exit
the current buffer or C-c C-i to automatically jump to the signature,
it will also color quotation and will of course enable auto-fill-mode
automatically. To enable mutt-mode automatically when writing a
message in mutt or slrn put mutt.el in your load-path and add
something like this to your Emacs startup file:

(defun mutt-mode-hook ()
(when
(and
(file-exists-p (buffer-file-name))
(stringp buffer-file-name)
(or (string-match (concat ".*mutt-comp-[0-9\-]+$") buffer-file-name)
(string-match ".followup" buffer-file-name)
(string-match ".article" buffer-file-name))
(mutt-mode)
)))

(add-hook 'find-file-hook 'mutt-mode-hook)

Replace `comp' with your hostname as by default mutt uses the hostname
to create a message template in /tmp.
--
Arkadiusz Drabczyk <***@drabczyk.org>
Jason
2017-08-16 16:16:37 UTC
Permalink
Post by Arkadiusz Drabczyk
Post by Luis Mochan
Post by Ian Zimmerman
Post by Jason
I am using emacs24 for my text editor with mutt (in a terminal).
How can I set it to automatically wrap the lines at a certain number
of characters?
"M-x auto-fill-mode" will do it in a new buffer, provided you set your
fill-column variable.
If you have already opened your buffer, you can wrap the lines of a paragraph with M-q.
You can set the fill column to say, 72 with C-u 7 2 C-x f
<Snipped my previous message and config>
Post by Arkadiusz Drabczyk
Is that your *whole* Emacs config?
As said above you need at least one hook. In order to easily use
Emacs in programs such as mutt or slrn I recommend mutt-mode. I
cannot find on the net anywhere any more so I put it here
http://drabczyk.org/mutt.el. mutt-mode will add several nice
keybindings such as C-c C-c to automatically save a message and exit
the current buffer or C-c C-i to automatically jump to the signature,
it will also color quotation and will of course enable auto-fill-mode
automatically. To enable mutt-mode automatically when writing a
message in mutt or slrn put mutt.el in your load-path and add
(defun mutt-mode-hook ()
(when
(and
(file-exists-p (buffer-file-name))
(stringp buffer-file-name)
(or (string-match (concat ".*mutt-comp-[0-9\-]+$") buffer-file-name)
(string-match ".followup" buffer-file-name)
(string-match ".article" buffer-file-name))
(mutt-mode)
)))
(add-hook 'find-file-hook 'mutt-mode-hook)
Replace `comp' with your hostname as by default mutt uses the hostname
to create a message template in /tmp.
Thank you Ian and Arkadiusz.

I implemented the above solution with 'mutt.el' and it works great. For
some reason C-c C-c does not work to exit though. It throws the
following error:

Symbol's function definition is void: server-edit
Is there an easy answer to that?

Thanks.
--
Jason
Ian Zimmerman
2017-08-16 19:13:12 UTC
Permalink
Post by Jason
Symbol's function definition is void: server-edit
Is there an easy answer to that?
That is very odd. In a normal emacs window, do "M-x apropos
server-edit". What do you get?

Where does your emacs come from? Binary package, what platform? Or
self-compiled?
--
Please don't Cc: me privately on mailing lists and Usenet,
if you also post the followup to the list or newsgroup.
Do obvious transformation on domain to reply privately _only_ on Usenet.
Jason
2017-08-17 01:53:52 UTC
Permalink
Post by Ian Zimmerman
Post by Jason
Symbol's function definition is void: server-edit
Is there an easy answer to that?
That is very odd. In a normal emacs window, do "M-x apropos
server-edit". What do you get?
I get "[No Match]"
Post by Ian Zimmerman
Where does your emacs come from? Binary package, what platform? Or
self-compiled?
Using Linux Mint 18 (64-bit). Emacs24 version 46.1 from the Ubuntu
repos.

Thanks.
--
Jason
Ian Zimmerman
2017-08-17 03:55:06 UTC
Permalink
Post by Jason
Post by Ian Zimmerman
That is very odd. In a normal emacs window, do "M-x apropos
server-edit". What do you get?
I get "[No Match]"
What is the output of the following, typed at a shell prompt?

ls -la /tmp/emacs$(id -u)
--
Please don't Cc: me privately on mailing lists and Usenet,
if you also post the followup to the list or newsgroup.
Do obvious transformation on domain to reply privately _only_ on Usenet.
Jason
2017-08-17 23:04:38 UTC
Permalink
Post by Ian Zimmerman
Post by Jason
Post by Ian Zimmerman
That is very odd. In a normal emacs window, do "M-x apropos
server-edit". What do you get?
I get "[No Match]"
What is the output of the following, typed at a shell prompt?
ls -la /tmp/emacs$(id -u)
$ ls -la /tmp/emacs$(id -u)
ls: cannot access '/tmp/emacs1000': No such file or directory

Thanks.
--
Jason
Ian Zimmerman
2017-08-17 23:47:49 UTC
Permalink
Post by Jason
$ ls -la /tmp/emacs$(id -u)
ls: cannot access '/tmp/emacs1000': No such file or directory
I should have asked to try that when emacs was running. Maybe you've
read my mind?

Is this the emacs-nox package maybe? It is possible, even likely, that
disabling X11 at compile time also disables the server feature. Since
mutt-mode seems to rely on it, you'll just have to install the full
emacs package to use mutt-mode without problems. (AFAIK it is possible
to install the full emacs on a system where X11 itself is not installed,
and it runs normally on a real terminal.)

And, not to be obnoxious, but why do you insist on mutt-mode anyway? It
is not distributed with emacs itself and thus not subject to the
stringent quality standard of emacs code. You just see some of the
effects of that right now :-P

message-mode, OTOH, has been in emacs for about 2 decades and is
accordingly battle tested.
--
Please don't Cc: me privately on mailing lists and Usenet,
if you also post the followup to the list or newsgroup.
Do obvious transformation on domain to reply privately _only_ on Usenet.
Jason
2017-08-18 02:00:19 UTC
Permalink
Post by Ian Zimmerman
Post by Jason
$ ls -la /tmp/emacs$(id -u)
ls: cannot access '/tmp/emacs1000': No such file or directory
I should have asked to try that when emacs was running. Maybe you've
read my mind?
I tried both ways, emacs running and not running; same result.
Post by Ian Zimmerman
Is this the emacs-nox package maybe? It is possible, even likely, that
disabling X11 at compile time also disables the server feature. Since
mutt-mode seems to rely on it, you'll just have to install the full
emacs package to use mutt-mode without problems. (AFAIK it is possible
to install the full emacs on a system where X11 itself is not installed,
and it runs normally on a real terminal.)
As far as I know, this is the full emacs package, though I'm a bit
confused about the difference between the emacs package and the emacs24
package. In mutt I am using it in the terminal by calling it as 'emacs
-nw' but if I change it to use the emacs GUI it makes no difference as
far as the problem I am having goes.
Post by Ian Zimmerman
And, not to be obnoxious, but why do you insist on mutt-mode anyway? It
For the simple reason that it was supplied by Arkadiusz Drabczyk with
instructions on how to set it up and I was able to get it to work, while
I wasn't sure how to implement message-mode on startup. Maybe one day
I'll have more time to explore how to customize emacs.
Post by Ian Zimmerman
is not distributed with emacs itself and thus not subject to the
stringent quality standard of emacs code. You just see some of the
effects of that right now :-P
message-mode, OTOH, has been in emacs for about 2 decades and is
accordingly battle tested.
In any case, the problem with C-c C-c not working is minor and while it
would be nice to know what's wrong, I can make out with C-x C-c and then
'y' for now.

Thanks!
--
Jason
Loading...