all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Lars Ingebrigtsen'" <larsi@gnus.org>, <emacs-devel@gnu.org>
Subject: RE: Unuseful keybindings
Date: Mon, 24 Dec 2012 13:43:50 -0800	[thread overview]
Message-ID: <B7BEC62B0A034A119E095DDEA282A645@us.oracle.com> (raw)
In-Reply-To: <8A240487C7BB4AABB55974CD69407C40@us.oracle.com>

[-- Attachment #1: Type: text/plain, Size: 1098 bytes --]

> > Speaking of odd key bindings, I just noticed that `home' goes to
> > the beginning of the line instead of the beginning of the buffer.
> 
> Now if `home' were bound to something like the following, 
> which is repeatable, then it would be a lot more useful.
> First time: bol, subsequently: next/previous line's bol.
> 
> (defun beginning-of-line+ ...
> http://www.emacswiki.org/emacs-en/download/misc-cmds.el

The attached code puts useful, repeatable keys on `C-a', `C-e', `home' and `end'
in `visual-line-mode'.  The `home' and `end' actions are presumably similar to
what is done in the greater world, except that you can repeat them to keep
moving.

Repeating `C-a' or `C-e' moves to the beginning/end of the previous/next visual
line.  Repeating `home' or `end' moves to the beginning/end of the previous/next
full logical line.  For non-repeated use, everything should be the same as
usual, including the use of a prefix arg.

IMHO, these commands are what Emacs should bind to `C-a', `C-e', `home', and
`end' in `visual-line-mode'.  I've added this code to `misc-cmds.el', in any
case.

[-- Attachment #2: throw-beg-end.el --]
[-- Type: application/octet-stream, Size: 4776 bytes --]

(defun end-of-line+ (&optional n)
  "Move cursor to end of current line or end of next line if repeated.
This is similar to `end-of-line', but:
  If called interactively with no prefix arg:
     If the previous command was also `end-of-line+', then move to the
     end of the next line.  Else, move to the end of the current line.
  Otherwise, move to the end of the Nth next line (Nth previous line
     if N<0).  Command `end-of-line', by contrast, moves to the end of
     the (N-1)th next line."
  (interactive
   (list (if current-prefix-arg (prefix-numeric-value current-prefix-arg) 0)))
  (unless n (setq n 0))                 ; non-interactive with no arg
  (if (and (eq this-command last-command) (not current-prefix-arg))
      (forward-line 1)
    (forward-line n))
  (let ((inhibit-field-text-motion  t))  (end-of-line)))

(defun beginning-of-line+ (&optional n)
  "Move cursor to beginning of current line or next line if repeated.
This is the similar to `beginning-of-line', but:
1. With arg N, the direction is the opposite: this command moves
   backward, not forward, N lines.
2. If called interactively with no prefix arg:
      If the previous command was also `beginning-of-line+', then move
      to the beginning of the previous line.  Else, move to the
      beginning of the current line.
   Otherwise, move to the beginning of the Nth previous line (Nth next
      line if N<0).  Command `beginning-of-line', by contrast, moves to
      the beginning of the (N-1)th next line."
  (interactive
   (list (if current-prefix-arg (prefix-numeric-value current-prefix-arg) 0)))
  (unless n (setq n 0))                 ; non-interactive with no arg
  (if (and (eq this-command last-command) (not current-prefix-arg))
      (forward-line -1)
    (forward-line (- n))))

(defun end-of-visual-line+ (&optional n)
  "Move cursor to end of current visual line, or end of next if repeated.
If point reaches the beginning or end of buffer, it stops there.
To ignore intangibility, bind `inhibit-point-motion-hooks' to t.

This is similar to `end-of-visual-line', but:
  If called interactively with no prefix arg:
     If the previous command was also `end-of-visual-line+', then move
     to the end of the next visual line.  Else, end of current one.
  Otherwise, move to the end of the Nth next visual line (Nth previous
     one if N<0).  Command `end-of-visual-line', by contrast, moves to
     the end of the (N-1)th next line."
  (interactive
   (list (if current-prefix-arg (prefix-numeric-value current-prefix-arg) 0)))
  (unless n (setq n 0))                 ; non-interactive with no arg 
  (let ((line-move-visual  t))
    (if (and (eq this-command last-command)  (not current-prefix-arg))
        (line-move 1 t)
      (line-move n t)))
  ;; Unlike `move-beginning-of-line', `move-end-of-line' doesn't
  ;; constrain to field boundaries, so we don't either.
  (vertical-motion (cons (window-width) 0)))

(defun beginning-of-visual-line+ (&optional n)
  "Move cursor to beginning of current visual line or next if repeated.
If point reaches the beginning or end of buffer, it stops there.
To ignore intangibility, bind `inhibit-point-motion-hooks' to t.

This is the similar to `beginning-of-visual-line', but:
1. With arg N, the direction is the opposite: this command moves
   backward, not forward, N visual lines.
2. If called interactively with no prefix arg:
      If the previous command was also `beginning-of-visual-line+',
      then move to the beginning of the previous visual line.  Else,
      move to the beginning of the current visual line.
   Otherwise, move to the beginning of the Nth previous visual line
      (Nth next one if N<0).  Command `beginning-of-visual-line', by
      contrast, moves to the beginning of the (N-1)th next visual
      line."
  (interactive
   (list (if current-prefix-arg (prefix-numeric-value current-prefix-arg) 0)))
  (unless n (setq n 0))                 ; non-interactive with no arg
  (let ((opoint  (point)))
    (let ((line-move-visual  t))
      (if (and (eq this-command last-command)  (not current-prefix-arg))
          (line-move -1 t)
        (line-move n t)))
    (vertical-motion 0)
    ;; Constrain to field boundaries, like `move-beginning-of-line'.
    (goto-char (constrain-to-field (point) opoint (/= n 1)))))

(define-key visual-line-mode-map [remap move-beginning-of-line] nil)
(define-key visual-line-mode-map [remap move-end-of-line] nil)
(define-key visual-line-mode-map [home] 'beginning-of-line+)
(define-key visual-line-mode-map [end]  'end-of-line+)
(define-key visual-line-mode-map "\C-a" 'beginning-of-visual-line+)
(define-key visual-line-mode-map "\C-e" 'end-of-visual-line+)

  reply	other threads:[~2012-12-24 21:43 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-18 13:00 Unuseful keybindings Thierry Volpiatto
2012-12-18 13:36 ` Andreas Schwab
2012-12-18 14:48   ` Thierry Volpiatto
2012-12-18 16:58     ` Sam Steingold
2012-12-18 19:30     ` Mathias Dahl
2012-12-18 19:37       ` Thierry Volpiatto
2012-12-22  3:22         ` Chong Yidong
2012-12-22  4:39           ` Drew Adams
2012-12-22  5:09             ` Xue Fuqiao
2012-12-22 21:24             ` Sebastien Vauban
2012-12-22 21:48               ` Dmitry Gutov
2012-12-22 22:46                 ` Drew Adams
2012-12-22 23:32                   ` Dmitry Gutov
2012-12-23  0:45                     ` Drew Adams
2012-12-23  1:07                       ` Xue Fuqiao
2012-12-23  1:19                         ` Daniel Colascione
2012-12-23  1:54                           ` advertizing keyboard macros better [was: Unuseful keybindings] Drew Adams
2012-12-23  2:10                             ` Xue Fuqiao
2012-12-23  9:29                       ` Unuseful keybindings Juri Linkov
2012-12-23 16:55                         ` Drew Adams
2012-12-26 14:32                           ` Kevin Rodgers
2012-12-26 22:21                             ` Xue Fuqiao
2012-12-27  3:42                               ` Eli Zaretskii
2012-12-23 14:41                       ` Dmitry Gutov
2012-12-23 14:57                         ` Jambunathan K
2012-12-23 16:52                           ` Drew Adams
2012-12-23 17:47                             ` Jambunathan K
2012-12-23 18:44                               ` Drew Adams
2012-12-23 19:36                                 ` Jambunathan K
2012-12-23 20:25                                 ` Jambunathan K
2012-12-23 21:04                                   ` Drew Adams
2012-12-24  9:35                                   ` Juri Linkov
2012-12-24 13:02                                     ` Xue Fuqiao
2012-12-24 14:13                                       ` Drew Adams
2012-12-23 17:03                         ` Drew Adams
2012-12-23 17:33                           ` Dmitry Gutov
2012-12-23 18:51                             ` Drew Adams
2012-12-23 20:53                             ` Lars Ingebrigtsen
2012-12-23 21:13                               ` Drew Adams
2012-12-24 21:43                                 ` Drew Adams [this message]
2012-12-23 21:25                               ` Andreas Schwab
2012-12-24  9:39                               ` Juri Linkov
2012-12-23 17:58                           ` Stephen J. Turnbull
2012-12-23 18:42                             ` Drew Adams
2012-12-23  0:19                   ` Mathias Dahl
2012-12-23  0:55                     ` Drew Adams
2012-12-23  9:32                 ` Juri Linkov
2012-12-23 10:37                   ` Xue Fuqiao
2012-12-23 10:56                     ` Dmitry Gutov
2012-12-23 11:22                       ` Xue Fuqiao
2012-12-22 22:28               ` Drew Adams
2012-12-22  7:42           ` Thierry Volpiatto
2012-12-22  8:23           ` Juri Linkov
2012-12-23  9:31             ` Juri Linkov
2012-12-24 10:29               ` Juri Linkov
2012-12-24 17:10                 ` Juri Linkov
2012-12-29  5:57                   ` Chong Yidong
2013-01-10 19:17                     ` Sam Steingold
2013-01-10 19:13                 ` Sam Steingold
2013-01-10 22:38                   ` Xue Fuqiao
2013-01-11  0:31                   ` Juri Linkov
2013-01-11  1:17                     ` Stefan Monnier
2013-01-11  9:58                       ` Juri Linkov
2013-01-11 14:42                         ` Stefan Monnier
2013-01-11 18:26                         ` chad
2013-01-12  0:50                           ` Juri Linkov
2013-01-12 10:03                             ` Jan Djärv
2013-01-13 10:19                               ` Juri Linkov
2013-01-13 11:19                                 ` Jan Djärv
2012-12-19  0:27       ` Drew Adams
2012-12-19  6:32         ` Thierry Volpiatto
2012-12-19 16:43         ` Leo
2012-12-18 13:40 ` Xue Fuqiao
2012-12-18 17:41 ` Eli Zaretskii
2012-12-18 17:49   ` Thierry Volpiatto
2012-12-18 19:10     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=B7BEC62B0A034A119E095DDEA282A645@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.