LoginSignup
3
3

More than 5 years have passed since last update.

ace-jump-modeでリージョン範囲を広げるためには

Last updated at Posted at 2015-07-29

ace-jump-modeでリージョン範囲を広げることを考える。つまり、C-SPCでマークをセットしてリージョンをアクティブにし、その後いくらかカーソルを移動すればリージョン範囲が広がることが確認できるが、ace-jump-modeでさらにその範囲を広げてみよう、ということである。これを実際にトライしてみるとすぐに分かるように、最新版ではace-jump-mode発動時のカーソル位置に常にマークをプッシュしてしまうため、リージョン範囲が期待した通りに広がらない。
(ただしace-jump-modeを適切なキーに設定している状況を想定。例えばC-c C-SPC

そこで以下のように関数を修正した。

(defun ace-jump-push-mark ()
  "Push the current position information onto the `ace-jump-mode-mark-ring'."
  ;; add mark to the emacs basic push mark

  ;; リージョンがアクティブのときはマークをプッシュしないように修正
  (unless (region-active-p)
    (push-mark (point) t))
  ;; 修正ここまで

  ;; we also push the mark on the `ace-jump-mode-mark-ring', which has
  ;; more information for better jump back
  (let ((pos (make-aj-position :offset (point)
                               :visual-area (make-aj-visual-area :buffer (current-buffer)
                                                                 :window (selected-window)
                                                                 :frame  (selected-frame)))))
    (setq ace-jump-mode-mark-ring (cons pos ace-jump-mode-mark-ring)))
  (if (> (length ace-jump-mode-mark-ring) ace-jump-mode-mark-ring-max)
      (setcdr (nthcdr (1- ace-jump-mode-mark-ring-max) ace-jump-mode-mark-ring) nil)))

リージョンがアクティブのときはマークをプッシュしない、というものである。上記関数を評価した後は期待通りにリージョン範囲を広げることができる。

余談だが、最近「画面内を素早くカーソル移動する方法のまとめ」で紹介したavyでもリージョンがアクティブ時の同様の問題点が指摘され、修正されている。むしろ本稿はこの修正に触発されて書いた。
avy.el (avy-action-goto): Don't push mark when region is active

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3