Chinaunix首页 | 论坛 | 博客
  • 博客访问: 184694
  • 博文数量: 43
  • 博客积分: 1150
  • 博客等级: 少尉
  • 技术积分: 450
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-29 15:52
文章分类

全部博文(43)

文章存档

2012年(18)

2011年(24)

2008年(1)

分类: LINUX

2011-09-15 22:00:30

(defgroup wlint nil
  "wlint interface for (X)Emacs.
Using wlint, you can easily search for where symbols are used and defined.
It is designed to answer questions like:

        Where is this variable used?
        What is the value of this preprocessor symbol?
        Where is this function in the source files?
        What functions call this function?
        What functions are called by this function?
        Where does the message \"out of space\" come from?
        Where is this source file in the directory structure?
        What files include this header file?
"
  :prefix "wlint-"
  :group 'tools)

(defvar wlint-output-buffer-name "*wlint*"
  "The name of the wlint output buffer.")

(defvar wlint-input-buffer-name "_LINT.TMP"
  "The name of the wlint output buffer.")

;;;;
;;;; Faces for fontification
;;;;
(defcustom wlint-use-face t
  "*Whether to use text highlighting (ॆ la font-lock) or not."
  :group 'wlint
  :type '(boolean))

(defface wlint-file-face
  '((((class color) (background dark))
     (:foreground "yellow"))
    (((class color) (background light))
     (:foreground "blue"))
    (t (:bold t)))
  "Face used to highlight file name in the *wlint* buffer."
  :group 'wlint)

(defface wlint-function-face
  '((((class color) (background dark))
     (:foreground "cyan"))
    (((class color) (background light))
     (:foreground "magenta"))
    (t (:bold t)))
  "Face used to highlight function name in the *wlint* buffer."
  :group 'wlint)

(defface wlint-line-number-face
  '((((class color) (background dark))
     (:foreground "red"))
    (((class color) (background light))
     (:foreground "red"))
    (t (:bold t)))
  "Face used to highlight line number in the *wlint* buffer."
  :group 'wlint)

(defface wlint-line-face
  '((((class color) (background dark))
     (:foreground "green"))
    (((class color) (background light))
     (:foreground "black"))
    (t (:bold nil)))
  "Face used to highlight the rest of line in the *wlint* buffer."
  :group 'wlint)

(defface wlint-mouse-face
  '((((class color) (background dark))
     (:foreground "white" :background "blue"))
    (((class color) (background light))
     (:foreground "white" :background "blue"))
    (t (:bold nil)))
  "Face used when mouse pointer is within the region of an entry."
  :group 'wlint)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Internal functions and variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defvar wlint-common-text-plist
  (let (plist)
    (setq plist (plist-put plist 'mouse-face 'wlint-mouse-face))
    plist)
  "List of common text properties to be added to the entry line.")

(defcustom wlint-name-line-width -30
  "*The width of the combined \"function name:line number\" field in the
cscope results buffer.  If negative, the field is left-justified."
  :type 'integer
  :group 'wlint)

(defcustom wlint-overlay-arrow-string "=>"
  "*The overlay string to use when displaying arrow overlays."
  :type 'string
  :group 'wlint)
(defun wlint-insert-with-text-properties (text filename &optional line-number)
  "Insert an entry with given TEXT, add entry attributes as text properties.
The text properties to be added:
- common property: mouse-face,
- properties are used to open target file and its location: wlint-file,
  wlint-line-number"
  (let ((plist wlint-common-text-plist)
 beg end)
    (setq beg (point))
    (insert text)
    (setq end (point)
   plist (plist-put plist 'wlint-file filename))
    (if line-number
 (progn
   (if (stringp line-number)
       (setq line-number (string-to-number line-number)))
   (setq plist (plist-put plist 'wlint-line-number line-number))
   ))
    (add-text-properties beg end plist)
    ))


(defun wlint-make-entry-line (func-name line-number line)
  (let* ((fmt (format "%%%ds %%s" wlint-name-line-width))
  (str (format fmt (format "%s[%s]" func-name line-number) line))
  beg end)
    (if wlint-use-face
 (progn
   (setq end (length func-name))
   (put-text-property 0 end 'face 'wlint-function-face str)
   (setq beg (1+ end)
  end (+ beg (length line-number)))
   (put-text-property beg end 'face 'wlint-line-number-face str)
   (setq end (length str)
  beg (- end (length line)))
   (put-text-property beg end 'face 'wlint-line-face str)
   ))
    str))

(defun wlint-show-entry-internal (file line-number
     &optional save-mark-p window arrow-p)
  "Display the buffer corresponding to FILE and LINE-NUMBER
in some window.  If optional argument WINDOW is given,
display the buffer in that WINDOW instead.  The window is
not selected.  Save point on mark ring before goto
LINE-NUMBER if optional argument SAVE-MARK-P is non-nil.
Put `overlay-arrow-string' if arrow-p is non-nil.
Returns the window displaying BUFFER."
  (let (buffer old-pos old-point new-point forward-point backward-point
        line-end line-length)
    (if (and (stringp file)
      (integerp line-number))
 (progn
   (unless (file-readable-p file)
     (error "%s is not readable or exists" file))
   (setq buffer (find-file-noselect file))
   (if (windowp window)
       (set-window-buffer window buffer)
     (setq window (display-buffer buffer)))
   (set-buffer buffer)
   (if (> line-number 0)
       (progn
  (setq old-pos (point))
  (goto-line line-number)
  (setq old-point (point))
  (set-window-point window old-point)
  ))
   )
      (message "No entry found at point."))
    )
  window)
(defvar wlint-list-entry-keymap nil
  "The keymap used in the *cscope* buffer which lists search results.")
(if wlint-list-entry-keymap
    nil
  (setq wlint-list-entry-keymap (make-keymap))
  (suppress-keymap wlint-list-entry-keymap)
  ;; The following section does not appear in the "Cscope" menu.
 
  (define-key wlint-list-entry-keymap [return] 'wlint-select-entry-other-window)
  ;; The previous line corresponds to be end of the "Cscope" menu.
  )


(defvar wlint-list-entry-hook nil
  "*Hook run after wlint-list-entry-mode entered.")


(defun wlint-list-entry-mode ()
  "Major mode for jumping/showing entry from the list in the *cscope* buffer.

}"
  (use-local-map wlint-list-entry-keymap)
  (setq buffer-read-only t
 mode-name "wlint"
 major-mode 'wlint-list-entry-mode
 overlay-arrow-string wlint-overlay-arrow-string)
  (or overlay-arrow-position
      (setq overlay-arrow-position (make-marker)))
  (run-hooks 'wlint-list-entry-hook))

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; functions in *cscope* buffer which lists the search results
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun wlint-select-entry-other-window ()
  "Display the entry at point in other window, select the window.
Push current point on mark ring and select the entry window."
  (interactive)
  (let ((file (get-text-property (point) 'wlint-file))
 (line-number (get-text-property (point) 'wlint-line-number))
 window)
    (setq window (wlint-show-entry-internal file line-number t))
    (if (windowp window)
 (select-window window))
    ))

(defun wlint-buffer-get-line (buffer-name)
  (let ((old-buffer (current-buffer)))
    (set-buffer buffer-name)
    (setq old-point (point))
    (setq line (buffer-substring-no-properties
  (progn
    (re-search-forward "^")
    (point))
  (progn
    (re-search-forward "^\\([^\n]*\\)")
    (point)
    )))
    (if(= old-point (point))
 (goto-char  (+ 1 (point)))
      t
      )
    (if (>= (point) (point-max))
 (setq line nil)
      line)
    (set-buffer old-buffer)
    line
    ))

(defun wlint-process-filter()
  (setq wlint-input-buffer-name (find-file "C:/Lint/_LINT.TMP" ))
  (set-buffer (get-buffer-create wlint-input-buffer-name))
  (goto-char (point-min))
  (setq outbuf (get-buffer-create wlint-output-buffer-name))
  (set-buffer outbuf)
  (setq buffer-read-only nil)
  (erase-buffer)
  (setq counter 0)
  (while (setq line (wlint-buffer-get-line wlint-input-buffer-name))
    (if (string-match "^\\([^ ]*()" line)
 (progn
   (setq file (substring line (match-beginning 1)
    (- (match-end 1) 1))
  line-number (substring line (match-beginning 2)
           (match-end 2)))
  (wlint-insert-with-text-properties
   (wlint-make-entry-line (concat (number-to-string counter) ":") line-number line)
   file
   line-number)
  (setq counter (1+ counter)))
      (insert line))
    (insert "\n")
    )
  (set-buffer-modified-p nil)
  (wlint-list-entry-mode)
  (kill-buffer wlint-input-buffer-name)
)

(wlint-process-filter)

阅读(1219) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~