⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtags.el

📁 代码检索工具GLOBAL源码。可用来浏览分析LINUX源码。
💻 EL
📖 第 1 页 / 共 2 页
字号:
;;; gtags.el --- gtags facility for Emacs;;;; Copyright (c) 1997, 1998, 1999, 2000 Tama Communications Corporation;;;; This file is part of GNU GLOBAL.;;;; GNU GLOBAL 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 2, or (at your option);; any later version.;;;; GNU GLOBAL 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, write to the Free Software;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.;;;; GLOBAL home page is at: http://www.gnu.org/software/global/;; Author: Tama Communications Corporation;; Version: 2.0;; Keywords: tools;; Gtags-mode is implemented as a minor mode so that it can work with any;; other major modes. Gtags-select mode is implemented as a major mode.;;;; Please copy this file into emacs lisp library directory or place it in;; a directory (for example "~/lisp") and write $HOME/.emacs like this.;;;;	(setq load-path (cons "~/lisp" load-path));;;; If you hope gtags-mode is on in c-mode then please add c-mode-hook to your;; $HOME/.emacs like this.;;;;	(setq c-mode-hook;;	    '(lambda ();;		(gtags-mode 1);;	));;; Code(defvar gtags-mode nil  "Non-nil if Gtags mode is enabled.")(make-variable-buffer-local 'gtags-mode)(defvar gtags-current-buffer nil  "Current buffer.")(defvar gtags-buffer-stack nil  "Stack for tag browsing.")(defvar gtags-point-stack nil  "Stack for tag browsing.")(defvar gtags-complete-list nil  "Gtags complete list.")(defvar gtags-history-list nil  "Gtags history list.")(defconst gtags-symbol-regexp "[A-Za-z_][A-Za-z_0-9]*"  "Regexp matching tag name.")(defconst gtags-definition-regexp "#[ \t]*define[ \t]+\\|ENTRY(\\|ALTENTRY("  "Regexp matching tag definition name.")(defvar gtags-read-only nil  "Gtags read only mode")(defvar gtags-mode-map (make-sparse-keymap)  "Keymap used in gtags mode.")(defvar gtags-running-xemacs (string-match "XEmacs\\|Lucid" emacs-version)  "Whether we are running XEmacs/Lucid Emacs")(defvar gtags-rootdir nil  "Root directory of source tree.");; New key assignment to avoid conflicting with ordinary assignments.;(define-key gtags-mode-map "\e*" 'gtags-pop-stack)(define-key gtags-mode-map "\e." 'gtags-find-tag);; Old key assignment.;; If you hope old style key assignment. Please include following code; to your $HOME/.emacs:;; (setq gtags-mode-hook;   '(lambda ();         (define-key gtags-mode-map "\eh" 'gtags-display-browser);         (define-key gtags-mode-map "\ec" 'gtags-make-complete-list);         (define-key gtags-mode-map "\C-]" 'gtags-find-tag-from-here);         (define-key gtags-mode-map "\C-t" 'gtags-pop-stack);         (define-key gtags-mode-map "\el" 'gtags-find-file);         (define-key gtags-mode-map "\eg" 'gtags-find-with-grep);         (define-key gtags-mode-map "\eI" 'gtags-find-with-idutils);         (define-key gtags-mode-map "\es" 'gtags-find-symbol);         (define-key gtags-mode-map "\er" 'gtags-find-rtag);         (define-key gtags-mode-map "\et" 'gtags-find-tag); ))(if (not gtags-running-xemacs) nil (define-key gtags-mode-map 'button3 'gtags-pop-stack) (define-key gtags-mode-map 'button2 'gtags-find-tag-by-event))(if gtags-running-xemacs nil (define-key gtags-mode-map [mouse-3] 'gtags-pop-stack) (define-key gtags-mode-map [mouse-2] 'gtags-find-tag-by-event))(defvar gtags-select-mode-map (make-sparse-keymap)  "Keymap used in gtags select mode.")(define-key gtags-select-mode-map "\e*" 'gtags-pop-stack)(if (not gtags-running-xemacs) nil (define-key gtags-select-mode-map 'button3 'gtags-pop-stack) (define-key gtags-select-mode-map 'button2 'gtags-select-tag-by-event))(if gtags-running-xemacs nil (define-key gtags-select-mode-map [mouse-3] 'gtags-pop-stack) (define-key gtags-select-mode-map [mouse-2] 'gtags-select-tag-by-event))(define-key gtags-select-mode-map "\^?" 'scroll-down)(define-key gtags-select-mode-map " " 'scroll-up)(define-key gtags-select-mode-map "\C-b" 'scroll-down)(define-key gtags-select-mode-map "\C-f" 'scroll-up)(define-key gtags-select-mode-map "k" 'previous-line)(define-key gtags-select-mode-map "j" 'next-line)(define-key gtags-select-mode-map "p" 'previous-line)(define-key gtags-select-mode-map "n" 'next-line)(define-key gtags-select-mode-map "q" 'gtags-pop-stack)(define-key gtags-select-mode-map "u" 'gtags-pop-stack)(define-key gtags-select-mode-map "\C-t" 'gtags-pop-stack)(define-key gtags-select-mode-map "\C-m" 'gtags-select-tag)(define-key gtags-select-mode-map "\e." 'gtags-select-tag);;;; utility;;(defun gtags-match-string (n)  (buffer-substring (match-beginning n) (match-end n)));; Return a default tag to search for, based on the text at point.(defun gtags-current-token ()  (cond   ((looking-at "[0-9A-Za-z_]")    (while (looking-at "[0-9A-Za-z_]")      (forward-char -1))    (forward-char 1))   (t    (while (looking-at "[ \t]")      (forward-char 1))))  (if (and (bolp) (looking-at gtags-definition-regexp))      (goto-char (match-end 0)))  (if (looking-at gtags-symbol-regexp)      (gtags-match-string 0) nil));; push current context to stack(defun gtags-push-context ()  (setq gtags-buffer-stack (cons (current-buffer) gtags-buffer-stack))  (setq gtags-point-stack (cons (point) gtags-point-stack)));; pop context from stack(defun gtags-pop-context ()  (if (not gtags-buffer-stack) nil    (let (buffer point)      (setq buffer (car gtags-buffer-stack))      (setq gtags-buffer-stack (cdr gtags-buffer-stack))      (setq point (car gtags-point-stack))      (setq gtags-point-stack (cdr gtags-point-stack))      (list buffer point))));; if the buffer exist in the stack(defun gtags-exist-in-stack (buffer)  (memq buffer gtags-buffer-stack));; is it a function?(defun gtags-is-function ()  (save-excursion    (while (and (not (eolp)) (looking-at "[0-9A-Za-z_]"))      (forward-char 1))    (while (and (not (eolp)) (looking-at "[ \t]"))      (forward-char 1))    (if (looking-at "(") t nil)));; is it a definition?(defun gtags-is-definition ()  (save-excursion    (if (and (string-match "\.java$" buffer-file-name) (looking-at "[^(]+([^)]*)[ \t]*{"))	t      (if (bolp)	  t        (forward-word -1)        (cond         ((looking-at "define")	  (forward-char -1)	  (while (and (not (bolp)) (looking-at "[ \t]"))	    (forward-char -1))	  (if (and (bolp) (looking-at "#"))	      t nil))         ((looking-at "ENTRY\\|ALTENTRY")	  (if (bolp) t nil)))))));;;; interactive command;;(defun gtags-visit-rootdir ()  "Tell tags commands the root directory of source tree."  (interactive)  (let (buffer input n)    (if (equal gtags-rootdir nil)      (save-excursion        (setq buffer (generate-new-buffer (generate-new-buffer-name "*rootdir*")))        (set-buffer buffer)        (setq n (call-process "global" nil t nil "-pr"))        (if (= n 0)          (setq gtags-rootdir (file-name-as-directory (buffer-substring (point-min)(1- (point-max)))))         (setq gtags-rootdir default-directory))        (kill-buffer buffer)))    (setq input (read-file-name "Visit root directory: "			gtags-rootdir gtags-rootdir t))    (if (equal "" input) nil      (if (not (file-directory-p input))        (message "%s is not directory." input)       (setq gtags-rootdir (expand-file-name input))       (setenv "GTAGSROOT" gtags-rootdir)))))(defun gtags-find-tag ()  "Input tag name and move to the definition."  (interactive)  (let (tagname prompt input)    (setq tagname (gtags-current-token))    (if tagname      (setq prompt (concat "Find tag: (default " tagname ") "))     (setq prompt "Find tag: "))    (setq input (completing-read prompt gtags-complete-list                  nil nil nil gtags-history-list))    (if (not (equal "" input))      (setq tagname input))    (gtags-push-context)    (gtags-goto-tag tagname "")))(defun gtags-find-rtag ()  "Input tag name and move to the referenced point."  (interactive)  (let (tagname prompt input)   (setq tagname (gtags-current-token))   (if tagname     (setq prompt (concat "Find tag (reference): (default " tagname ") "))    (setq prompt "Find tag (reference): "))   (setq input (completing-read prompt gtags-complete-list                 nil nil nil gtags-history-list))   (if (not (equal "" input))     (setq tagname input))    (gtags-push-context)    (gtags-goto-tag tagname "r")))(defun gtags-find-symbol ()  "Input symbol and move to the locations."  (interactive)  (let (tagname prompt input)    (setq tagname (gtags-current-token))    (if tagname        (setq prompt (concat "Find symbol: (default " tagname ") "))      (setq prompt "Find symbol: "))    (setq input (completing-read prompt gtags-complete-list                  nil nil nil gtags-history-list))    (if (not (equal "" input)) (setq tagname input))    (gtags-push-context)    (gtags-goto-tag tagname "s")))(defun gtags-find-pattern ()  "Input pattern, search with grep(1) and move to the locations."  (interactive)  (gtags-find-with-grep))(defun gtags-find-with-grep ()  "Input pattern, search with grep(1) and move to the locations."  (interactive)  (gtags-find-with "g"))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -