Subject: 23.2; Home and End keys don't work as expected with both pc-selection-mode and visual-line-mode enabled
From: PJ Weisberg <[email-masked]>
To: [email-masked]
Date: Sat, 29 Jan 2011 21:00:09 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

1) Open or create a file with logical lines longer than the width of the
window.
2) Enable visual-line-mode and pc-selection-mode (order doesn't matter).
3) Press the <home> and/or <end> keys with point on one of these long
lines.

Expected: Point moves to the beginning/end of the current visual line.
Observed: Point moves to the beginning/end of the current logical line.

I've attached two (mutually exclusive) patches against the trunk.  I've
never submitted a patch to Emacs before, so please let me know which is more
in line with the preferred way of doing things.

--PJ
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: [email-masked]\
#   nuvqsje84yncvflq
# target_branch: bzr://bzr.savannah.gnu.org/emacs/trunk/
# testament_sha1: b4d2fcdcc523cadc51d5f47e1965a9610cfcb2db
# timestamp: 2011-01-29 20:56:16 -0800
# base_revision_id: [email-masked]\
#   jminwifpi767oiw5
# 
# Begin patch
=== modified file 'lisp/emulation/pc-select.el'
--- lisp/emulation/pc-select.el	2011-01-25 04:08:28 +0000
+++ lisp/emulation/pc-select.el	2011-01-30 04:55:42 +0000
@@ -366,8 +366,11 @@
 If scan reaches end of buffer, stop there without error."
   (interactive "p")
   (pc-select-ensure-mark)
-  (end-of-line arg)
-  (setq this-command 'end-of-line))
+  (let ((eol-command (if visual-line-mode
+                         'end-of-visual-line
+                       'end-of-line)))
+    (funcall eol-command arg)
+    (setq this-command eol-command)))
 
 (defun backward-line-mark (&optional arg)
   "Ensure mark is active; move cursor vertically up ARG lines."
@@ -501,8 +504,11 @@
 If scan reaches end of buffer, stop there without error."
   (interactive "p")
   (pc-select-maybe-deactivate-mark)
-  (end-of-line arg)
-  (setq this-command 'end-of-line))
+  (let ((eol-command (if visual-line-mode
+                         'end-of-visual-line
+                       'end-of-line)))
+    (funcall eol-command arg)
+    (setq this-command eol-command)))
 
 (defun backward-line-nomark (&optional arg)
   "Deactivate mark; move cursor vertically up ARG lines."
@@ -628,8 +634,9 @@
 If scan reaches end of buffer, stop there without error."
   (interactive "p")
   (pc-select-ensure-mark)
-  (beginning-of-line arg))
-
+  (if visual-line-mode
+      (beginning-of-visual-line arg)
+    (beginning-of-line arg)))
 
 (defun scroll-up-mark (&optional arg)
   "Ensure mark is active; scroll upward ARG lines; or near full screen if no ARG.
@@ -728,7 +735,9 @@
 If scan reaches end of buffer, stop there without error."
   (interactive "p")
   (pc-select-maybe-deactivate-mark)
-  (beginning-of-line arg))
+  (if visual-line-mode
+      (beginning-of-visual-line arg)
+    (beginning-of-line arg)))
 
 (defun scroll-up-nomark (&optional arg)
   "Deactivate mark; scroll upward ARG lines; or near full screen if no ARG.

# Begin bundle
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: [email-masked]\
#   r8qs1ccpbbbsbg1e
# target_branch: bzr://bzr.savannah.gnu.org/emacs/trunk/
# testament_sha1: 10ade64307d860af931f9f6fd8d3162c0b4d71e1
# timestamp: 2011-01-29 19:42:53 -0800
# base_revision_id: [email-masked]\
#   jminwifpi767oiw5
# 
# Begin patch
=== modified file 'lisp/emulation/pc-select.el'
--- lisp/emulation/pc-select.el	2011-01-25 04:08:28 +0000
+++ lisp/emulation/pc-select.el	2011-01-30 03:31:00 +0000
@@ -369,6 +369,15 @@
   (end-of-line arg)
   (setq this-command 'end-of-line))
 
+(defun end-of-visual-line-mark (&optional arg)
+  "Ensure mark is active; move point to end of current visual line.
+With argument ARG not nil or 1, move forward ARG - 1 lines first.
+If scan reaches end of buffer, stop there without error."
+  (interactive "p")
+  (pc-select-ensure-mark)
+  (end-of-visual-line arg)
+  (setq this-command 'end-of-visual-line))
+
 (defun backward-line-mark (&optional arg)
   "Ensure mark is active; move cursor vertically up ARG lines."
   (interactive "p")
@@ -504,6 +513,15 @@
   (end-of-line arg)
   (setq this-command 'end-of-line))
 
+(defun end-of-visual-line-nomark (&optional arg)
+  "Deactivate mark; move point to end of current visual line.
+With argument ARG not nil or 1, move forward ARG - 1 lines first.
+If scan reaches end of buffer, stop there without error."
+  (interactive "p")
+  (pc-select-maybe-deactivate-mark)
+  (end-of-visual-line arg)
+  (setq this-command 'end-of-visual-line))
+
 (defun backward-line-nomark (&optional arg)
   "Deactivate mark; move cursor vertically up ARG lines."
   (interactive "p")
@@ -630,6 +648,13 @@
   (pc-select-ensure-mark)
   (beginning-of-line arg))
 
+(defun beginning-of-visual-line-mark (&optional arg)
+  "Ensure mark is active; move point to beginning of current visual line.
+With argument ARG not nil or 1, move forward ARG - 1 lines first.
+If scan reaches end of buffer, stop there without error."
+  (interactive "p")
+  (pc-select-ensure-mark)
+  (beginning-of-visual-line arg))
 
 (defun scroll-up-mark (&optional arg)
   "Ensure mark is active; scroll upward ARG lines; or near full screen if no ARG.
@@ -730,6 +755,14 @@
   (pc-select-maybe-deactivate-mark)
   (beginning-of-line arg))
 
+(defun beginning-of-visual-line-nomark (&optional arg)
+  "Deactivate mark; move point to beginning of current visual line.
+With argument ARG not nil or 1, move forward ARG - 1 lines first.
+If scan reaches end of buffer, stop there without error."
+  (interactive "p")
+  (pc-select-maybe-deactivate-mark)
+  (beginning-of-visual-line arg))
+
 (defun scroll-up-nomark (&optional arg)
   "Deactivate mark; scroll upward ARG lines; or near full screen if no ARG.
 A near full screen is `next-screen-context-lines' less than a full screen.

=== modified file 'lisp/simple.el'
--- lisp/simple.el	2011-01-25 04:08:28 +0000
+++ lisp/simple.el	2011-01-30 03:31:00 +0000
@@ -4808,6 +4808,10 @@
     (define-key map [remap kill-line] 'kill-visual-line)
     (define-key map [remap move-beginning-of-line] 'beginning-of-visual-line)
     (define-key map [remap move-end-of-line]  'end-of-visual-line)
+    (define-key map [remap end-of-line-nomark] 'end-of-visual-line-nomark)
+    (define-key map [remap end-of-line-mark] 'end-of-visual-line-mark)
+    (define-key map [remap beginning-of-line-nomark] 'beginning-of-visual-line-nomark)
+    (define-key map [remap beginning-of-line-mark] 'beginning-of-visual-line-mark)
     ;; These keybindings interfere with xterm function keys.  Are
     ;; there any other suitable bindings?
     ;; (define-key map "\M-[" 'previous-logical-line)

# Begin bundle