emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C-n and C-a


From: Juri Linkov
Subject: Re: C-n and C-a
Date: Fri, 06 Feb 2009 02:45:17 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.90 (x86_64-pc-linux-gnu)

Below is a patch that addresses part of problems raised on
this thread.  (I'll send a separate patch for another part later).

First, it adds a new prefix map bound to `C-x l' for line-oriented
commands, and rebinds `count-lines-page' to `C-x l p'.

There was an old commented-out line for the `narrow-to-page' command
bound to `C-x p' that was later rebound to `C-x n p'.  Now we will have
a symmetrical key `C-x l p' for another page-related command.  Also it
binds more line-oriented commands to `C-x l': `toggle-truncate-lines'
to `C-x l t', `toggle-word-wrap' to `C-x l w' and `visual-line-mode'
to `C-x l v'.

`toggle-word-wrap' is a new command.  Actually it's just a copy of
`toggle-truncate-lines' that operates on the variable `word-wrap'
instead of `truncate-lines'.  By analogy with `default-truncate-lines'
it also adds a new variable `default-word-wrap'.

The default value of `word-wrap' is changed to t that is the most
expected default value nowadays as most editors do.  This eliminates
the need to enforce enabling word-mode in `visual-line-mode'.
The essential point of `visual-line-mode' is only to turn off
`truncate-lines' since otherwise it makes no sense.  The doc string
now says so.

Index: lisp/bindings.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/bindings.el,v
retrieving revision 1.218
diff -c -r1.218 bindings.el
*** lisp/bindings.el    29 Jan 2009 08:53:39 -0000      1.218
--- lisp/bindings.el    6 Feb 2009 00:41:24 -0000
***************
*** 718,723 ****
--- 718,727 ----
  (define-key narrow-map "n" 'narrow-to-region)
  (define-key narrow-map "w" 'widen)
  
+ (defvar line-map (make-sparse-keymap)
+   "Keymap for line-oriented commands.")
+ (define-key ctl-x-map "l" line-map)
+ 
  ;; Quitting
  (define-key global-map "\e\e\e" 'keyboard-escape-quit)
  (define-key global-map "\C-g" 'keyboard-quit)
***************
*** 1092,1098 ****
  (define-key esc-map "\C-a" 'beginning-of-defun)
  (define-key esc-map "\C-e" 'end-of-defun)
  (define-key esc-map "\C-h" 'mark-defun)
! (define-key ctl-x-map "nd" 'narrow-to-defun)
  (define-key esc-map "(" 'insert-parentheses)
  (define-key esc-map ")" 'move-past-close-and-reindent)
  
--- 1098,1104 ----
  (define-key esc-map "\C-a" 'beginning-of-defun)
  (define-key esc-map "\C-e" 'end-of-defun)
  (define-key esc-map "\C-h" 'mark-defun)
! (define-key narrow-map "d" 'narrow-to-defun)
  (define-key esc-map "(" 'insert-parentheses)
  (define-key esc-map ")" 'move-past-close-and-reindent)
  
***************
*** 1121,1129 ****
  (define-key ctl-x-map "[" 'backward-page)
  (define-key ctl-x-map "]" 'forward-page)
  (define-key ctl-x-map "\C-p" 'mark-page)
! (define-key ctl-x-map "l" 'count-lines-page)
! (define-key ctl-x-map "np" 'narrow-to-page)
! ;; (define-key ctl-x-map "p" 'narrow-to-page)
  
  (defvar abbrev-map (make-sparse-keymap)
    "Keymap for abbrev commands.")
--- 1127,1138 ----
  (define-key ctl-x-map "[" 'backward-page)
  (define-key ctl-x-map "]" 'forward-page)
  (define-key ctl-x-map "\C-p" 'mark-page)
! (define-key narrow-map "p" 'narrow-to-page)
! (define-key line-map   "p" 'count-lines-page)
! 
! (define-key line-map "t" 'toggle-truncate-lines)
! (define-key line-map "w" 'toggle-word-wrap)
! (define-key line-map "v" 'visual-line-mode)
  
  (defvar abbrev-map (make-sparse-keymap)
    "Keymap for abbrev commands.")

Index: lisp/simple.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/simple.el,v
retrieving revision 1.968
diff -c -r1.968 simple.el
*** lisp/simple.el      27 Jan 2009 20:09:38 -0000      1.968
--- lisp/simple.el      6 Feb 2009 00:42:16 -0000
***************
*** 4550,4556 ****
  
  (define-minor-mode visual-line-mode
    "Redefine simple editing commands to act on visual lines, not logical lines.
! This also turns on `word-wrap' in the buffer."
    :keymap visual-line-mode-map
    :group 'visual-line
    :lighter " wrap"
--- 4560,4566 ----
  
  (define-minor-mode visual-line-mode
    "Redefine simple editing commands to act on visual lines, not logical lines.
! This also turns off `truncate-lines' in the buffer."
    :keymap visual-line-mode-map
    :group 'visual-line
    :lighter " wrap"
***************
*** 4562,4580 ****
        ;; visual-line-mode is turned off.
        (dolist (var '(line-move-visual truncate-lines
                       truncate-partial-width-windows
!                      word-wrap fringe-indicator-alist))
          (if (local-variable-p var)
              (push (cons var (symbol-value var))
                    visual-line--saved-state)))
        (set (make-local-variable 'line-move-visual) t)
        (set (make-local-variable 'truncate-partial-width-windows) nil)
        (setq truncate-lines nil
-             word-wrap t
              fringe-indicator-alist
              (cons (cons 'continuation visual-line-fringe-indicators)
                    fringe-indicator-alist)))
      (kill-local-variable 'line-move-visual)
-     (kill-local-variable 'word-wrap)
      (kill-local-variable 'truncate-lines)
      (kill-local-variable 'truncate-partial-width-windows)
      (kill-local-variable 'fringe-indicator-alist)
--- 4572,4588 ----
        ;; visual-line-mode is turned off.
        (dolist (var '(line-move-visual truncate-lines
                       truncate-partial-width-windows
!                      fringe-indicator-alist))
          (if (local-variable-p var)
              (push (cons var (symbol-value var))
                    visual-line--saved-state)))
        (set (make-local-variable 'line-move-visual) t)
        (set (make-local-variable 'truncate-partial-width-windows) nil)
        (setq truncate-lines nil
              fringe-indicator-alist
              (cons (cons 'continuation visual-line-fringe-indicators)
                    fringe-indicator-alist)))
      (kill-local-variable 'line-move-visual)
      (kill-local-variable 'truncate-lines)
      (kill-local-variable 'truncate-partial-width-windows)
      (kill-local-variable 'fringe-indicator-alist)
***************
*** 5075,5080 ****
--- 5083,5103 ----
    (message "Truncate long lines %s"
           (if truncate-lines "enabled" "disabled")))
  
+ (defun toggle-word-wrap (&optional arg)
+   "Toggle whether to use word-wrapping for continuation lines.
+ With prefix argument ARG, wrap continuation lines at word boundaries
+ if ARG is positive, otherwise wrap them at the right screen edge.
+ This command toggles the value of `word-wrap'.  It has no effect
+ if long lines are truncated."
+   (interactive "P")
+   (setq word-wrap
+       (if (null arg)
+           (not word-wrap)
+         (> (prefix-numeric-value arg) 0)))
+   (force-mode-line-update)
+   (message "Word wrapping %s"
+          (if word-wrap "enabled" "disabled")))
+ 
  (defvar overwrite-mode-textual " Ovwrt"
    "The string displayed in the mode line when in overwrite mode.")
  (defvar overwrite-mode-binary " Bin Ovwrt"

Index: src/buffer.c
===================================================================
RCS file: /sources/emacs/emacs/src/buffer.c,v
retrieving revision 1.579
diff -c -r1.579 buffer.c
*** src/buffer.c        8 Jan 2009 03:15:25 -0000       1.579
--- src/buffer.c        6 Feb 2009 00:44:28 -0000
***************
*** 5175,5181 ****
  
    XSETFASTINT (buffer_defaults.tab_width, 8);
    buffer_defaults.truncate_lines = Qnil;
!   buffer_defaults.word_wrap = Qnil;
    buffer_defaults.ctl_arrow = Qt;
    buffer_defaults.direction_reversed = Qnil;
    buffer_defaults.cursor_type = Qt;
--- 5175,5181 ----
  
    XSETFASTINT (buffer_defaults.tab_width, 8);
    buffer_defaults.truncate_lines = Qnil;
!   buffer_defaults.word_wrap = Qt;
    buffer_defaults.ctl_arrow = Qt;
    buffer_defaults.direction_reversed = Qnil;
    buffer_defaults.cursor_type = Qt;
***************
*** 5540,5545 ****
--- 5540,5550 ----
                     doc: /* Default value of `truncate-lines' for buffers that 
do not override it.
  This is the same as (default-value 'truncate-lines).  */);
  
+   DEFVAR_LISP_NOPRO ("default-word-wrap",
+                    &buffer_defaults.word_wrap,
+                    doc: /* Default value of `word-wrap' for buffers that do 
not override it.
+ This is the same as (default-value 'word-wrap).  */);
+ 
    DEFVAR_LISP_NOPRO ("default-fill-column",
                     &buffer_defaults.fill_column,
                     doc: /* Default value of `fill-column' for buffers that do 
not override it.

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]