comparison lisp/simple.el @ 103862:b760b8569489

* simple.el (temporary-goal-column): Change the value for line-move-visual to a cons cell. (line-move-visual): Record or set the window hscroll, if necessary (Bug#3494). (line-move-1): Handle cons value of temporary-goal-column.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 11 Jul 2009 16:36:05 +0000
parents 695df25d3fc1
children 687539bbd810
comparison
equal deleted inserted replaced
103861:2359749268a7 103862:b760b8569489
3971 (make-variable-buffer-local 'goal-column) 3971 (make-variable-buffer-local 'goal-column)
3972 3972
3973 (defvar temporary-goal-column 0 3973 (defvar temporary-goal-column 0
3974 "Current goal column for vertical motion. 3974 "Current goal column for vertical motion.
3975 It is the column where point was at the start of the current run 3975 It is the column where point was at the start of the current run
3976 of vertical motion commands. It is a floating point number when 3976 of vertical motion commands.
3977 moving by visual lines via `line-move-visual'; this is the 3977
3978 x-position, in pixels, divided by the default column width. When 3978 When moving by visual lines via `line-move-visual', it is a cons
3979 the `track-eol' feature is doing its job, the value is 3979 cell (COL . HSCROLL), where COL is the x-position, in pixels,
3980 divided by the default column width, and HSCROLL is the number of
3981 columns by which window is scrolled from left margin.
3982
3983 When the `track-eol' feature is doing its job, the value is
3980 `most-positive-fixnum'.") 3984 `most-positive-fixnum'.")
3981 3985
3982 (defcustom line-move-ignore-invisible t 3986 (defcustom line-move-ignore-invisible t
3983 "Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines. 3987 "Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines.
3984 Outline mode sets this." 3988 Outline mode sets this."
4073 ;; Arg says how many lines to move. The value is t if we can move the 4077 ;; Arg says how many lines to move. The value is t if we can move the
4074 ;; specified number of lines. 4078 ;; specified number of lines.
4075 (defun line-move-visual (arg &optional noerror) 4079 (defun line-move-visual (arg &optional noerror)
4076 (let ((posn (posn-at-point)) 4080 (let ((posn (posn-at-point))
4077 (opoint (point)) 4081 (opoint (point))
4082 (hscroll (window-hscroll))
4078 x) 4083 x)
4079 ;; Reset temporary-goal-column, unless the previous command was a 4084 ;; Check if the previous command was a line-motion command, or if
4080 ;; line-motion command or we were called from some other command. 4085 ;; we were called from some other command.
4081 (unless (and (floatp temporary-goal-column) 4086 (cond ((and (consp temporary-goal-column)
4082 (memq last-command `(next-line previous-line ,this-command))) 4087 (memq last-command `(next-line previous-line ,this-command)))
4083 (cond ((eq (nth 1 posn) 'right-fringe) ; overflow-newline-into-fringe 4088 ;; If so, there's no need to reset `temporary-goal-column',
4084 (setq temporary-goal-column (- (window-width) 1))) 4089 ;; unless the window hscroll has changed.
4085 ((setq x (car (posn-x-y posn))) 4090 (when (/= hscroll (cdr temporary-goal-column))
4086 (setq temporary-goal-column (/ (float x) (frame-char-width)))))) 4091 (set-window-hscroll nil 0)
4092 (setq temporary-goal-column
4093 (cons (+ (car temporary-goal-column)
4094 (cdr temporary-goal-column)) 0))))
4095 ;; Otherwise, we should reset `temporary-goal-column'.
4096 ;; Handle the `overflow-newline-into-fringe' case:
4097 ((eq (nth 1 posn) 'right-fringe)
4098 (setq temporary-goal-column (cons (- (window-width) 1) hscroll)))
4099 ((setq x (car (posn-x-y posn)))
4100 (setq temporary-goal-column
4101 (cons (/ (float x) (frame-char-width)) hscroll))))
4087 ;; Move using `vertical-motion'. 4102 ;; Move using `vertical-motion'.
4088 (or (and (= (vertical-motion 4103 (or (and (= (vertical-motion
4089 (cons (or goal-column (truncate temporary-goal-column)) arg)) 4104 (cons (or goal-column
4105 (if (consp temporary-goal-column)
4106 (truncate (car temporary-goal-column))
4107 temporary-goal-column))
4108 arg))
4090 arg) 4109 arg)
4091 (or (>= arg 0) 4110 (or (>= arg 0)
4092 (/= (point) opoint) 4111 (/= (point) opoint)
4093 ;; If the goal column lies on a display string, 4112 ;; If the goal column lies on a display string,
4094 ;; `vertical-motion' advances the cursor to the end 4113 ;; `vertical-motion' advances the cursor to the end
4106 ;; Don't run any point-motion hooks, and disregard intangibility, 4125 ;; Don't run any point-motion hooks, and disregard intangibility,
4107 ;; for intermediate positions. 4126 ;; for intermediate positions.
4108 (let ((inhibit-point-motion-hooks t) 4127 (let ((inhibit-point-motion-hooks t)
4109 (opoint (point)) 4128 (opoint (point))
4110 (orig-arg arg)) 4129 (orig-arg arg))
4111 (if (floatp temporary-goal-column) 4130 (if (consp temporary-goal-column)
4112 (setq temporary-goal-column (truncate temporary-goal-column))) 4131 (setq temporary-goal-column (+ (car temporary-goal-column)
4132 (cdr temporary-goal-column))))
4113 (unwind-protect 4133 (unwind-protect
4114 (progn 4134 (progn
4115 (if (not (memq last-command '(next-line previous-line))) 4135 (if (not (memq last-command '(next-line previous-line)))
4116 (setq temporary-goal-column 4136 (setq temporary-goal-column
4117 (if (and track-eol (eolp) 4137 (if (and track-eol (eolp)