aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2008-07-17 23:37:50 +0000
committerChong Yidong2008-07-17 23:37:50 +0000
commita2cf21a2c4be6e2cc843e41a0f80dc1a63e46c96 (patch)
treed11b6fb75b30fb270b7c450a01e9e989b89db361
parent55f337b5c734b725f0f8184f0c49375310a98a9c (diff)
downloademacs-a2cf21a2c4be6e2cc843e41a0f80dc1a63e46c96.tar.gz
emacs-a2cf21a2c4be6e2cc843e41a0f80dc1a63e46c96.zip
(line-move-visual): Make it a defcustom.
(line-move-1): Convert temporary-goal-column back to an integer if it was set as a float by a previous call to line-move-visual. (end-of-visual-line, beginning-of-visual-line, kill-visual-line) (next-logical-line, previous-logical-line) (turn-on-visual-line-mode): New functions. (visual-line-mode-map): New variable. (visual-line-mode, global-visual-line-mode): New minor mode.
-rw-r--r--lisp/simple.el131
1 files changed, 129 insertions, 2 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index c7622954037..f429b1321c3 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3906,11 +3906,13 @@ Outline mode sets this."
3906 :type 'boolean 3906 :type 'boolean
3907 :group 'editing-basics) 3907 :group 'editing-basics)
3908 3908
3909(defvar line-move-visual t 3909(defcustom line-move-visual t
3910 "When non-nil, `line-move' moves point by visual lines. 3910 "When non-nil, `line-move' moves point by visual lines.
3911This movement is based on where the cursor is displayed on the 3911This movement is based on where the cursor is displayed on the
3912screen, instead of relying on buffer contents alone. It takes 3912screen, instead of relying on buffer contents alone. It takes
3913into account variable-width characters and line continuation.") 3913into account variable-width characters and line continuation."
3914 :type 'boolean
3915 :group 'editing-basics)
3914 3916
3915;; Returns non-nil if partial move was done. 3917;; Returns non-nil if partial move was done.
3916(defun line-move-partial (arg noerror to-end) 3918(defun line-move-partial (arg noerror to-end)
@@ -4017,6 +4019,8 @@ into account variable-width characters and line continuation.")
4017 (let ((inhibit-point-motion-hooks t) 4019 (let ((inhibit-point-motion-hooks t)
4018 (opoint (point)) 4020 (opoint (point))
4019 (orig-arg arg)) 4021 (orig-arg arg))
4022 (if (floatp temporary-goal-column)
4023 (setq temporary-goal-column (truncate temporary-goal-column)))
4020 (unwind-protect 4024 (unwind-protect
4021 (progn 4025 (progn
4022 (if (not (memq last-command '(next-line previous-line))) 4026 (if (not (memq last-command '(next-line previous-line)))
@@ -4365,7 +4369,130 @@ The goal column is stored in the variable `goal-column'."
4365 ) 4369 )
4366 nil) 4370 nil)
4367 4371
4372;;; Editing based on visual lines, as opposed to logical lines.
4373
4374(defun end-of-visual-line (&optional n)
4375 "Move point to end of current visual line.
4376With argument N not nil or 1, move forward N - 1 visual lines first.
4377If point reaches the beginning or end of buffer, it stops there.
4378To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
4379 (interactive "^p")
4380 (or n (setq n 1))
4381 (if (/= n 1)
4382 (let ((line-move-visual t))
4383 (line-move (1- n) t)))
4384 (vertical-motion (cons (window-width) 0)))
4385
4386(defun beginning-of-visual-line (&optional n)
4387 "Move point to beginning of current visual line.
4388With argument N not nil or 1, move forward N - 1 visual lines first.
4389If point reaches the beginning or end of buffer, it stops there.
4390To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
4391 (interactive "^p")
4392 (or n (setq n 1))
4393 (if (/= n 1)
4394 (let ((line-move-visual t))
4395 (line-move (1- n) t)))
4396 (vertical-motion 0))
4397
4398(defun kill-visual-line (&optional arg)
4399 "Kill the rest of the visual line.
4400If there are only whitespace characters there, kill through the
4401newline as well.
4402
4403With prefix argument, kill that many lines from point.
4404Negative arguments kill lines backward.
4405With zero argument, kill the text before point on the current line.
4406
4407When calling from a program, nil means \"no arg\",
4408a number counts as a prefix arg.
4409
4410If `kill-whole-line' is non-nil, then this command kills the whole line
4411including its terminating newline, when used at the beginning of a line
4412with no argument. As a consequence, you can always kill a whole line
4413by typing \\[beginning-of-line] \\[kill-line].
4414
4415If you want to append the killed line to the last killed text,
4416use \\[append-next-kill] before \\[kill-line].
4417
4418If the buffer is read-only, Emacs will beep and refrain from deleting
4419the line, but put the line in the kill ring anyway. This means that
4420you can use this command to copy text from a read-only buffer.
4421\(If the variable `kill-read-only-ok' is non-nil, then this won't
4422even beep.)"
4423 (interactive "P")
4424 (let ((opoint (point))
4425 (line-move-visual t)
4426 end)
4427 ;; It is better to move point to the other end of the kill before
4428 ;; killing. That way, in a read-only buffer, point moves across
4429 ;; the text that is copied to the kill ring. The choice has no
4430 ;; effect on undo now that undo records the value of point from
4431 ;; before the command was run.
4432 (if arg
4433 (vertical-motion (prefix-numeric-value arg))
4434 (if (eobp)
4435 (signal 'end-of-buffer nil))
4436 (setq end (save-excursion
4437 (end-of-visual-line) (point)))
4438 (if (or (save-excursion
4439 ;; If trailing whitespace is visible,
4440 ;; don't treat it as nothing.
4441 (unless show-trailing-whitespace
4442 (skip-chars-forward " \t" end))
4443 (= (point) end))
4444 (and kill-whole-line (bolp)))
4445 (line-move 1)
4446 (goto-char end)))
4447 (kill-region opoint (point))))
4448
4449(defun next-logical-line (&optional arg try-vscroll)
4450 "Move cursor vertically down ARG lines.
4451This is identical to `previous-line', except that it always moves
4452by logical lines instead of visual lines, ignoring the value of
4453the variable `line-move-visual'."
4454 (interactive "^p\np")
4455 (let ((line-move-visual nil))
4456 (with-no-warnings
4457 (next-line arg try-vscroll))))
4458
4459(defun previous-logical-line (&optional arg try-vscroll)
4460 "Move cursor vertically up ARG lines.
4461This is identical to `previous-line', except that it always moves
4462by logical lines instead of visual lines, ignoring the value of
4463the variable `line-move-visual'."
4464 (interactive "^p\np")
4465 (let ((line-move-visual nil))
4466 (with-no-warnings
4467 (previous-line arg try-vscroll))))
4368 4468
4469(defvar visual-line-mode-map
4470 (let ((map (make-sparse-keymap)))
4471 (define-key map [remap kill-line] 'kill-visual-line)
4472 (define-key map [remap move-beginning-of-line] 'beginning-of-visual-line)
4473 (define-key map [remap move-end-of-line] 'end-of-visual-line)
4474 (define-key map "\M-[" 'previous-logical-line)
4475 (define-key map "\M-]" 'next-logical-line)
4476 map))
4477
4478(define-minor-mode visual-line-mode
4479 "Define key binding for visual line moves."
4480 :keymap visual-line-mode-map
4481 :group 'convenience
4482 (if visual-line-mode
4483 (progn
4484 (set (make-local-variable 'line-move-visual) t)
4485 (setq word-wrap t))
4486 (kill-local-variable 'line-move-visual)
4487 (kill-local-variable 'word-wrap)))
4488
4489(defun turn-on-visual-line-mode ()
4490 (visual-line-mode 1))
4491
4492(define-globalized-minor-mode global-visual-line-mode
4493 visual-line-mode turn-on-visual-line-mode
4494 :lighter " vl")
4495
4369(defun scroll-other-window-down (lines) 4496(defun scroll-other-window-down (lines)
4370 "Scroll the \"other window\" down. 4497 "Scroll the \"other window\" down.
4371For more details, see the documentation for `scroll-other-window'." 4498For more details, see the documentation for `scroll-other-window'."