[2009-01-20-1] の補完。
ver22 までの Emacs のカーソル移動は論理行単位なので、こんなのを使っ
てます。時々移動がミスりますが、そこはご愛嬌ということで。
(defvar vz-goal-column 0 "Vz風ゴールカラム")
(defvar vz-enable-p t "*Enable the physical moving.")
(defun toggle-variable (var)
"Toggle '(symbol-value var)'."
(set var (not (symbol-value var)))
(message "'%s' is now '%s'"
(symbol-name var) (symbol-value var)))
(defun vz-toggle-vz-enable-p ()
"Toggle 'vz-enable-p'."
(interactive)
(toggle-variable 'vz-enable-p))
(defun vz-next-line (num)
"Vz:↓"
(interactive "p")
(if (or (not vz-enable-p) truncate-lines)
(next-line num)
(or (eq last-command 'vz-next-line)
(setq vz-goal-column (% (current-column) (1- (window-width)))))
(if (eolp)
(progn
(forward-char 1)
(move-to-column vz-goal-column))
(vertical-motion num)
(move-to-column (+ vz-goal-column (current-column))))))
(defun vz-previous-line (num)
"Vz:↑"
(interactive "p")
(if (not vz-enable-p)
(previous-line num)
(if truncate-lines
(previous-line num)
(or (eq last-command 'vz-next-line)
(setq vz-goal-column (% (current-column) (1- (window-width)))))
(let ((ncol (- vz-goal-column (window-width) -1)))
(vertical-motion (- num))
(if (<= 0 ncol)
(move-to-column ncol)
(move-to-column (+ vz-goal-column (current-column))))))
(setq this-command 'vz-next-line))) ;fake
情報源:
極私的 Emacs カスタマイズ紹介マガヂン Emacs をわたし色に染めて♪
第 16 回 物理行単位のカーソル移動 〜vz.el から一部を流用する〜