Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With visual-line-mode enabled in Emacs, long lines wrap at natural breaks in the text, allowing me to see all of the text on any given line. Wrap appears in my status bar. Sometimes I want to the lines to not wrap. I can toggle that state by command: M-x visual-line-mode. However, when I do that, C-e does not take me to the end of the line, but instead somewhere towards a "screenwidth" or so, though it seems to be variable.

I can fix that problem by calling M-x toggle-truncate-lines after running the M-x visual-line-mode, but what I'd like to do is use a single Function key command to run both commands in sequence.

In my .emacs file I currently have this:

(global-set-key [f8] 'toggle-truncate-lines)
(global-set-key [f9] 'visual-line-mode)

With these keys defined, I can use the function keys f9 and f8 in sequence to get the results I want. I thought I could write an elisp function to call the two functions in sequence, and then map a single function key to that function, like so:

(defun unwrap-lines ()
  "Unwrap lines, and fix the C-e not to the end problem"

(global-set-key [f10] 'unwrap-lines)

However, after defining this function, it seems to only call the second command in my function toggle-truncate-lines, and skips the visual-line-mode aspect of the function.

What am I doing wrong?

share|improve this question
Visual line mode is turned off with (visual-line-mode -1) You might also want to make sure that you are not using global-visual-line-mode which affects everything. – lawlist Dec 28 '13 at 3:23
Thatnks! That was the part I was missing. – Andrew Larned Dec 28 '13 at 15:46

You must log in to answer this question.

Browse other questions tagged .