11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Emacs で過去のカーソル位置を記憶・閲覧・選択・移動する

Last updated at Posted at 2019-03-24

過去に訪れた箇所にカーソルを戻したいってとき、ありますよね。
point-undo.el などの便利 package もありますが、同じ buffer の中を飛び回ったり、色々な buffer を移動したりすると、戻りたい箇所を見失う時も多々あります。

そのため、過去に訪れた箇所の一覧をリストとして表示して、そこから戻りたい箇所を選択できる package を作りました。
本体は GitHub/point-history に置いておきます(PR や issue 待ってます!)

追記: 2019/04/21更新

これは何?

カーソルが一定時間留まった位置を、履歴として保存しておきます。
その履歴から一つ選択することで、再度その箇所(buffer, position)にカーソルを移動させることができます。
また、履歴を別ウィンドウでプレビューできます。 <== NEW!
point-history

特徴

  • ある一定時間カーソルが留まった箇所(point-info)を、履歴として保存しておきます
  • point-info はバッファ名、カーソル位置、その行の文字列等を保持しています
  • point-info の履歴を一覧として表示し、そのうち一つを選択することで、その箇所にジャンプできます
  • カーソル行の履歴を、別ウィンドウでプレビューできます <== NEW!

設定

事前準備

popwin-el を使っているため、事前に popwin-el をインストールする必要があります。

本設定

git clone して init.el を以下のように編集するだけです。

(add-to-list 'load-path "YOUR PATH")
(require 'point-history)

;; enable minor mode
(point-history-mode t)

;; お好みで
(global-set-key (kbd "YOUR KEY") 'point-history-show)

使い方

M-x point-history-show を実行することで履歴一覧の buffer が開きます。
ジャンプしたい箇所を選択して Enter を入力すると、ジャンプできます。

Screen Shot 2019-03-24 at 13.45.44.png

point-history-show-buffer での keymap をお好みで変更することも可能です。 <== NEW!

(define-key point-history-show-mode-map (kbd "n") 'point-history-next-line)
(define-key point-history-show-mode-map (kbd "p") 'point-history-prev-line)

カスタマイズ

いくつかカスタム可能な変数を用意しています。
(point-history-should-preview を追加しました) <== NEW!

variable usage default value
point-history-max-item-num Max number of points saved in history 100
point-history-show-buffer-height Buffer height to show point-history 30
point-history-save-timer Interval time to save point in history 1
point-history-should-preview show the preview of buffers t

その他

point-history-ignore-bufferpoint-history-ignore-major-mode を以下のように設定することで、特定の buffer や major-mode での point を履歴に保存することを禁止できます。 <== NEW!

(setq point-history-ignore-buffer "^ \\*Minibuf\\|^ \\*point-history-show*")
(setq point-history-ignore-major-mode '(emacs-lisp-mode ruby-mode))

参考

この package は point-undo.el「Qiita/前回1秒以上立ち止まった場所にジャンプするコマンド」 を大いに参考にして作らせていただきました。ありがとうございました。

11
7
6

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
11
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?