這裏是我的解決方案,這不正是正如你所問。
如果你是emacs的新手,只需將下面的代碼複製到你的.emacs文件,然後M-x eval-buffer
就可以在這個文件上了,這應該是全局的。
當使用前綴參數(例如C-u f2
)調用F1-F12鍵時,或者當該鍵的書籤不存在時,將爲該鍵創建書籤。否則,該點跳轉到請求的書籤。
要循環,首先按[C-tab],然後用[tab]繼續循環。
要僅爲某些緩衝區安裝它,您必須找到要使用它們的模式的掛鉤,並將bookmark_fkey_install
添加到這些掛鉤。
(defun bookmark_fkey (force_store)
(interactive "P")
(let* ((fkey (this-command-keys-vector))
(curr_val (gethash fkey bookmark_fkey_hash nil)))
(when (equal 21 (elt fkey 0))
(setq fkey (vector (elt fkey 1)))); should really be 'cdr' of vector
(if (or force_store (not curr_val))
(progn
(message (format "Setting new bookmark for %s" fkey))
(puthash fkey (point) bookmark_fkey_hash)
(setq bookmark_fkey_sorted nil)
)
(progn
(message (format "Moving point to %d" curr_val))
(goto-char curr_val)))
)
)
(defun bookmark_fkey_cycle () (interactive)
(let (sorted index continue p C)
(setq p (point))
(setq sorted (sort (maphashL (lambda (x y) y) bookmark_fkey_hash) (lambda (a b) (< a b))))
(setq index (sum (mapcar (lambda (bp) (if (< bp p) 1 0)) sorted)))
(setq continue t)
(setq C (length sorted))
(while (and continue C)
(goto-char (nth (mod index C) sorted))
(setq index (1+ index))
(setq continue (equal [9] (read-key-sequence-vector "Press tab to keep cyclivng"))))
))
(defun bookmark_fkey_install (&optional use_global)
(interactive "P")
(setq bookmark_fkey_hash (make-hash-table :test 'equal))
(make-variable-buffer-local 'bookmark_fkey_hash)
(setq map (if use_global global-map (current-local-map)))
;(mapc 'make-variable-buffer-local (list 'bookmark_fkey_hash 'bookmark_fkey_sorted 'bookmark_fkey_index))
(setq fkey (list [f1] [f2] [f3] [f4] [f5] [f6] [f7] [f8] [f9] [f10] [f11] [f12]))
(mapc (lambda (k) (define-key map k 'bookmark_fkey)) fkey)
(define-key map [C-tab] 'bookmark_fkey_cycle)
)
(bookmark_fkey_install t)
其實,我認爲[The Mark Ring](http://www.gnu.org/software/emacs/manual/html_node/emacs/Mark-Ring.html#Mark-Ring)中描述的行爲幾乎完全就像要求的一樣。 'C-SPC''C-SPC'創建無名書籤,並且'C-u''C-SPC'循環遍歷它們。 (唯一的問題是,您將設置標記的次數比您想要設置書籤的次數多) –