2013-10-04 46 views
2

有沒有一種方法可以與emacs中的Textmate書籤功能具有相同的行爲?emacs上的Textmate書籤行爲

在Textmate中,我爲一行(用F鍵 - 不需要命名)添加一行後,可以用另一個F鍵返回給它(不需要命名書籤)。除此之外,我可以在一個頁面上放幾個unamed書籤,通過它們的cicle只需按下「前往書籤」F Key即可。

讓我們打破了一個問題:

  • 這是可能的書籤線路上的一個文件,而不需要他們,而不需要按RET名字?
  • 在單個文件上可能有幾個unamed書籤?
  • 它們之間有可能會凝結,也不需要按下RET?

在此先感謝! :)

回答

3

你問:

  • 這是可能的書籤線路上的一個文件,而不需要他們的名字和無需按RET?
  • 在單個文件上可能有幾個unamed書籤?
  • 它們之間有可能會凝結,也不需要按下RET?

是的,是的,是的。還有更多---使用Bookmark+

對於前兩個問題,請參閱關於autonamed bookmarks的文檔部分。有關第三個問題,請參閱關於cycling的章節(例如,當前緩衝區中的自動化書籤)。

0

我會說「位置寄存器」是emacs的方式。 http://www.gnu.org/software/emacs/manual/html_node/emacs/Position-Registers.html#Position-Registers

一個更簡單的替代方法是使用該商標,但它是一個不同的方式來保存和跳躍的位置,因爲他們沒有相關的名稱/鍵: http://www.gnu.org/software/emacs/manual/html_node/emacs/Mark.html

+0

其實,我認爲[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'循環遍歷它們。 (唯一的問題是,您將設置標記的次數比您想要設置書籤的次數多) –

0

這裏是我的解決方案,這不正是正如你所問。

如果你是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) 
+0

只注意到我沒有解決騎車問題。這應該是直截了當的。 – erjoalgo

+0

騎行現在也適用。請讓我知道這是否適合你。我實際上正在考慮自己使用這個,儘管我確實使用了'F1'鍵,也許我只需要習慣默認的'C-h'。 – erjoalgo