less について新たに覚えたこと
どうもです。
以前,「Emacs 内で,global-mark-ring の中身を表示して,ひょいひょいと移動できる
インターフェイスがあれば便利だよ」,って言ったのに,誰も作ってくれないから,
自分で作ってます。
こんな風に,global-mark-ring の内容を表示して,選択して,移動する感じです。
調べたら,*mark* バッファを用意してそこで選択させるみたいなのは,
EmacsWiki にあった。
mark-ring の場合は,C-uC-SPC 連打でなんとかなる。
タグジャンプとか grep の結果とかでどっかのバッファに飛んだときに,
元いたバッファに,C-b で戻ると,カーソルの位置が元いた場所と異なるときがございます。
というのは建前で,popup.el を使ってみたかったのと,自分自身,もっそい需要があったから。
使ってみた感想は,うーん・・・微妙だ。
現在は,marker 内のポイントのある行を表示するようにしているけど,
あまりナビゲートに役立ってない気がする。
けど,popup.el のおかげで,候補を表示して,C-s でファイル名で絞れば,
わかりやすい。
2つ関数書いただけだけど,なんか公開してみたいので,公開してみた。
後悔しなければいいんだけど。更改することは間違いない。
てーか,よくわからんが,コードの前に色々コピペしたりして,書き加えてみた。
こんな感じでいいんだろうか。
まともになったら,EmacsWiki にアップロードしてみたい。wktk。
;;; popup-global-mark-ring.el --- Jumping Interactively through global mark ring ;; Copyright (C) 2010 whitypig ;; Author: whitypig <whitypig@gmail.com> ;; Keywords: lisp popup ;; Version: 0.1 ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. ;;; Commentary: ;; ;; This software is greatly inspired by popup-kill-ring ;; and created thanks to popup.el, ;; so I'd like to express my gratitude to its authors. ;; ;; Apparently, there still are many bugs, so please be generous. ;;; Requirement: ;; ;; * popup.el http://github.com/m2ym/auto-complete ;;; Installation: ;; ;; Copy popup-global-mark-ring.el to your load-path and add to your .emacs: ;; ;; (require 'popup-global-mark-ring) ;; ;; To use popup-global-mark-ring, do M-x popup-global-mark-ring. ;; Or assign the key whatever you want to to 'popup-global-mark-ring. ;; For example, ;; (global-set-key "\C-c\C-g" 'popup-global-mark-ring) ;;; Code: (require 'popup) ;;; Variables: (defvar popup-global-mark-ring-menu-width 70 "Width of popup menu") ;;; Functions: (defun popup-global-mark-ring () "Show global mark ring menu and go to the place selected." (interactive) (let ((item nil) (num 0)) ;; Show menu and get selection (setq item (and global-mark-ring (popup-menu* (popup-global-mark-ring-menu) :scroll-bar t :margin t :width popup-global-mark-ring-menu-width))) (when item (when (string-match "^\\([0-9]+\\):.*" item) (setq num (1- (string-to-number (match-string 1 item)))) (setq marker (nth num global-mark-ring)) ;; Make current-location maker from the current location ;; and push it into mark-ring if it is not (setq current-marker (point-marker)) (unless (and (marker-position current-marker) (member current-marker global-mark-ring)) (push-mark)) ;; now, switch to and go to the place specified by the marker (switch-to-buffer (marker-buffer marker)) (goto-char (marker-position marker)))))) ;; TODO (defun popup-global-mark-ring-current ()) ;; TODO (defun popup-global-mark-ring-next ()) ;; TODO (defun popup-global-mark-ring-prev ()) (defun popup-global-mark-ring-menu () "Return the list of lines with each line containing marker info. Iterating `global-mark-ring', make and return a list consisting of marker information that can be acquired from each element in `global-mark-ring'" (interactive) (let ((ret nil) (i 1)) (dolist (elt global-mark-ring) (let ((pos (marker-position elt)) (bufname (buffer-name (marker-buffer elt))) (linenum 0) (start 0) (end 0)) ;; exclude #<marker in no buffer> (when (and pos bufname) (save-excursion (set-buffer bufname) (setq linenum (line-number-at-pos pos)) (goto-char pos) (beginning-of-line) (setq start (point)) (end-of-line) (setq end (point)) (add-to-list 'ret (format "%d:(%s:%d):%s" i bufname linenum (buffer-substring-no-properties start end)) t)) (setq i (1+ i))))) ret)) (provide 'popup-global-mark-ring) ;;; popup-global-mark-ring.el ends here
本題
なんか疲れちゃったね。
本題。
less -N .emacs で,行番号表示。
早速 alias しとく。
alias lesn='less -N'
j, k とか,移動系では,prefix-argument みたいなのが使える。
8j, 8k とか。vi ユーザにとっては当たり前だったりしそうな予感。
「=」 で行数とかファイルの情報表示とかね。
あとなんかあったけど,忘れた。
結局,less --help してくだちい,というオチ。
ああ,思い出した。g に prefix つけて,行番号指定して,ジャンプとか。
そのためには,-N しておかないと,あまりうれしくないかもねぇ〜。
ちなみに,lv は,-n オプションあるけど,効かなかったりする?
オレだけかな。
まとめ
popup.el があればこそ。というか,ワタシはほとんど何もしてない感じが
しないでもない感じ。
auto-complete.el でもお世話になっているし,どうもありがとう。
あと,popup-kill-ring の作者様にも感謝。コード参考にさせてもらってます。