开发者

Stop emacs from wrapping 80 column lines in an 80 column terminal?

In an 80 column wide terminal emacs wraps 80 column lines, putting a backslash in the 80th co开发者_C百科lumn. Is there a way to tell emacs to use all 80 columns of my terminal and not wrap lines until they reach 81 characters?


If I understand this question correctly, this is not about logical line wrapping (how lines are segmented in your file), but about visual wrapping (how lines are displayed with respect to window width).

  • If you just want the display to visually wrap more than zero characters before window boundary, and thus avoid the backslash everywhere, however long your logical lines really are, you can use longlines-mode :

    Unlike Visual Line mode, Long Lines mode breaks long lines at the fill column (see Fill Commands), rather than the right window edge. To enable Long Lines mode, type M-x longlines-mode. If the text is full of long lines, this also immediately “wraps” them all.

    Then, it's only a matter of setting the fill-column appropriately, using either global settings (.emacs, though you probably want to use a specific mode-hook for that particular case), local settings (file variable, dir-locals) or C-u 79 C-uC-x f to set variable fill-column to 79. This way, lines 79 characters or higher will wrap, but before touching the right edge of the 80-char window (and thus never leaving an ugly backslash character). Your file will be untouched.

  • If you simply want no visual wrapping to occur on 80-character lines, and thus do not want the 80th logical character visually displayed below the first, there are two possible answers:

    • either you work in an environment where you don't necessarily wrap logically at or before 80 characters, and you want to see the end of those 81+ lines somewhere in your screen (i.e. you do want visual wrap, but at a number of chars above the window width), then I don't know how to do it.

    • or you want to stop your lines at 80 chars logically (e.g. you have auto-fill on and fill-column at 80), and if you do happen to have lines 81 characters or more, you don't care about seeing their ending. In that case, activate truncate-mode (toggle-truncate-lines).

  • If the issue is about the last character of your window, and what you really want is the 80th logical character of your line to be displayed on the 80th visual character of your window, though, I'm afraid I don't know how. Either you are truncating lines (as above), and the last character of your window will be a $, or you let emacs do its thing, and the last character will be a backslash.

Note when testing that auto-fill's wrapping (but also longlines-mode's, since it is its visual equivalent) will occur only at word boundaries.


One option is to set the wrapping to happen at 81, instead of 80.

M-x set-fill-column RET 81

Another option, maybe the best choice, is to define the variable overflow-newline-into-fringe as t. Try this once, manually:

M-x set-variable RET overflow-newline-into-fringe RET t

Either of these could be set by default. You can do that through M-x customize or by editing your .emacs file. Post again if you need help.

BTW, do you use emacs in a graphical or terminal environment? In a graphical environment, I often just make the window larger if I have long lines. Or I may turn on line truncation with a horizontal scrollbar.


added later

With the added information that you are running emacs in terminal mode, as you discovered, none of those options work. I tried an example running emacs in putty, where I can change the size of the window and emacs picks it right up. So, I could size to 81 columns and my 80-column lines remain intact without continuation. I am not sure which TERM value you have assigned with tmux, but you could consider creating a custom terminal type (termcap or terminfo) which supports 81 columns. I only took a brief glance at tmux but I noticed that you can resize panes within a terminal.

Now, out of curiosity, what is the primary motivator for you using tmux? I would think that the resume capability would be valuable. I would find however, that the other features are not that useful because in an X-Window environment it is cheap & easy to open more terminals or if I am using putty, I can create more of those. As far as using emacs, whether I am running under X-Window or MS-Windows, I just create as many frames as I would like and can work quite easily with that. So, is there something else that makes you interested in using tmux?


Six years after the previous answers and the workaround I still use is to use 81 character-wide windows.

Unfortunately 80-wide windows that wrap 'correctly' are not possible because of evil fringe characters. Emacs requires the last (fringe) character to have exclusive use of the final column. The argument for this is an optional fringe character is ambiguous. I dream of the day someone will submit a patch to make the fringe character optional, and perhaps solving the ambiguity with a background color.


I don't think that is prossible in general, because emacs needs at least one character to indicate that the line continues in the next line (wraps), although I'm not sure, because emacs has so many options... You could maybe instead select "Word Wrap (Visual Line Mode)" in the "Options" menu (or keyboard):

M-x visual-line-modeRET

This makes the flow more natural, without showing (at least in text modes) the indication of wrapping.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜