Domanda

Suppose I have a file with the following marks (or call it tags):

test.el:

;; =====
;; gnus:

some code here

;; ====
;; ECB:

some code here

;; =====
;; code:

some code here

(in elisp)

test.py:

# ========
# imports:

some code here

# =====
# defs:

some code here

# =====
# args:

some code here

(in python)

So I'd like to have a buffer which would list such tags (or call it marks) for a given buffer/file. And it should also facilitate navigation thru this tags in some way - with a mouse or keybindings (something similar to the table of contents functionality of rest-mode).

I wanted to solve this problem by modifing some etags function. But couldn't find one (that would be a solution since ECB shows etags nicely in a buffer - just as I wanted).

Some other solution might have been using bookmarks - but bookmarks are not file-specific. They are system-specific. That is in bookmark-list You have all the bookmarks - while I wanted to get the bookmarks of the given file only.

È stato utile?

Soluzione

Using the Emacs Lisp example code, I solved it with the following that could be added to a hook for emacs-lisp-mode, and should be easy to tweak for other languages.

(make-local-variable 'outline-regexp)
(setq outline-regexp ";; =+\n;; ")
(make-local-variable 'outline-heading-end-regexp)
(setq outline-heading-end-regexp ":\n")
(outline-minor-mode 1)

You can now use standard outline mode, which has keybindings like this:

C-c @ C-p  -> prevous header
C-c @ C-n  -> next header

C-c @ C-t  -> hide code between headers
C-c @ C-a  -> show all the code between headers

If you temporarily hide the headers, you will get an outline of your buffer, move where you want, then show the code again.

For python, just replace the ;; in the regexp with #.

outline-mode comes with Emacs, and is documented there if you need more information.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top