Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 120 lines (104 sloc) 3.701 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
(defvar taglist-mode-hook nil)

(defvar taglist-keywords
  (list (list "^\t\\([^ ]*\\) \\(L[0-9]+\\) *\\(.*\\)$" 1 font-lock-keyword-face)
        (list "^\t\\([^ ]*\\) \\(L[0-9]+\\) *\\(.*\\)$" 2 font-lock-comment-delimiter-face)
        (list "^\t\\([^ ]*\\) \\(L[0-9]+\\) *\\(.*\\)$" 3 font-lock-function-name-face)))

(defvar taglist-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "RET") 'taglist-jump)
    (define-key map (kbd "q") 'taglist-quit)
    map))

(defvar taglist-window nil)
(defvar taglist-current 0)

(defun taglist nil
  (interactive)
  (require 'speedbar)
  (require 'imenu)

  ;; Clear cache
  (setq imenu--index-alist nil)

  (let ((source-buffer (current-buffer))
        (current-line (line-number-at-pos)))

    ;; Create a buffer
    (if (get-buffer "*etags tmp*")
        (kill-buffer "*etags tmp*"))
    (if (get-buffer "*etags list*")
        (kill-buffer "*etags list*"))
    (set-buffer (get-buffer-create "*etags list*"))

    ;; Call speedbar tags
    (setq taglist-current 0)
    (taglist-fill-tags
     source-buffer
     (cddr (speedbar-fetch-dynamic-tags
            (buffer-file-name source-buffer)))
     ""
     current-line)

    (goto-char (point-min))
    (forward-line (1- taglist-current))

    (setq taglist-window (split-window-vertically))
    (set-window-buffer taglist-window "*etags list*")
    (select-window taglist-window)
    (taglist-mode)))

(defun taglist-fill-tags (source-buffer tags prefix current)
  (while tags
    (if (integer-or-marker-p (cdar tags))
        (let ((tag-line
               (with-current-buffer source-buffer
                 (line-number-at-pos (cdar tags)))))
          (insert (format "\t%s L%-5d%s%s\n"
                          (buffer-name source-buffer)
                          tag-line
                          prefix
                          (caar tags)))
          (when (>= current tag-line)
            (setq taglist-current
                  (1+ taglist-current))))
      (let* ((dir-string (caar tags))
             (marker (get-text-property 0 'org-imenu-marker dir-string))
             (tag-line 0))
        (if marker
          (setq tag-line
                (with-current-buffer source-buffer
                  (line-number-at-pos marker))))
        (insert (format "\t%s L%-5d%s%s\n"
                        (buffer-name source-buffer)
                        tag-line
                        prefix
                        (caar tags)))
        (when (>= current tag-line)
          (setq taglist-current
                (1+ taglist-current)))
        (taglist-fill-tags source-buffer
                           (cdar tags)
                           (concat "+-" prefix)
                           current)))
    (setq tags (cdr tags))))

(defun taglist-kill nil
  (if (and taglist-window
           (window-live-p taglist-window)
           (not (one-window-p)))
      (delete-window taglist-window))
  (setq taglist-window nil)
  (kill-buffer "*etags list*"))

(defun taglist-jump nil
  (interactive)
  (let ((line (buffer-substring
               (line-beginning-position)
               (line-end-position))))
    (string-match "^\t\\([^ ]*\\) L\\([0-9]+\\)[^0-9]" line)
    (taglist-kill)
    (switch-to-buffer (match-string 1 line))
    (goto-char (point-min))
    (forward-line (1- (string-to-number (match-string 2 line))))))

(defun taglist-quit nil
  (interactive)
  (taglist-kill))

(defun taglist-mode nil
  (interactive)
  (kill-all-local-variables)
  (use-local-map taglist-map)
  (setq major-mode 'taglist-mode)
  (setq mode-name "Tag-List")
  (setq font-lock-defaults
        (list 'taglist-keywords))
  (run-mode-hooks 'taglist-mode-hook))

(provide 'taglist)
Something went wrong with that request. Please try again.