which-function-mode cannot work with official CEDET 2.0

扶醉桌前 提交于 2021-02-10 06:55:59

问题


I have installed official CEDET 2.0 using el-get on GNU Emacs 24.3 and configured it. Although it works great for code jump and completion, it cannot work properly with Emacs built-in which-function-mode. When the major modes is Java mode, the Emacs mode line simply displays [???], like no valid function is recognized. But when I removed my CEDET configuration, which-function-mode works well. So I think the problem should be related to the official CEDET 2.0. I tried to manually enable which-function-mode, the problem is still persist.

I cannot figure out where it goes wrong with my configuration.

Can anyone help? Thanks.

Update: If I disabled semantic by commenting out the line (semantic-mode 1), which-function-mode would work. I checked the CEDET documents, the semantic is enabled in the way as I did.

(add-to-list 'load-path (concat cedet-root-path "contrib"))

(add-to-list 'semantic-default-submodes 'global-semantic-mru-bookmark-mode)
(add-to-list 'semantic-default-submodes 'global-semanticdb-minor-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-scheduler-mode)
(add-to-list 'semantic-default-submodes 'global-cedet-m3-minor-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-highlight-func-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-local-symbol-highlight-mode)

;; Activate semantic
(semantic-mode 1)

;; Load contrib library
(require 'eassist)

(when (not (member system-type '(gnu gnu/linux darwin cygwin)))
  (if (executable-find "gcc")
      (semantic-gcc-setup)
    (message "GCC is not installed and semantic analysis will be restriced.")))

(setq pulse-flag 'never)  ; No fade in/out effect
(setq semanticdb-default-save-directory
      (expand-file-name "~/.emacs.d/semanticdb"))
(setq eassist-header-switches
      '(("h" . ("cpp" "cxx" "c++" "CC" "cc" "C" "c" "mm" "m"))
        ("hh" . ("cc" "CC" "cpp" "cxx" "c++" "C"))
        ("hpp" . ("cpp" "cxx" "c++" "cc" "CC" "C"))
        ("hxx" . ("cxx" "cpp" "c++" "cc" "CC" "C"))
        ("h++" . ("c++" "cpp" "cxx" "cc" "CC" "C"))
        ("H" . ("C" "CC" "cc" "cpp" "cxx" "c++" "mm" "m"))
        ("HH" . ("CC" "cc" "C" "cpp" "cxx" "c++"))
        ("cpp" . ("hpp" "hxx" "h++" "HH" "hh" "H" "h"))
        ("cxx" . ("hxx" "hpp" "h++" "HH" "hh" "H" "h"))
        ("c++" . ("h++" "hpp" "hxx" "HH" "hh" "H" "h"))
        ("CC" . ("HH" "hh" "hpp" "hxx" "h++" "H" "h"))
        ("cc" . ("hh" "HH" "hpp" "hxx" "h++" "H" "h"))
        ("C" . ("hpp" "hxx" "h++" "HH" "hh" "H" "h"))
        ("c" . ("h"))
        ("m" . ("h"))
        ("mm" . ("h"))))


;; Save the current jump point in order to jump back when using CEDET
;; http://comments.gmane.org/gmane.emacs.cedet/5127
(defvar semantic-tags-location-ring (make-ring 512))

(defun semantic-goto-definition (point)
  "Goto definition using semantic-ia-fast-jump
save the pointer marker if tag is found"
  (interactive "d")
  (condition-case err
      (progn
        (ring-insert semantic-tags-location-ring (point-marker))
        (semantic-ia-fast-jump point))
    (error
     ;;if not found remove the tag saved in the ring
     (set-marker (ring-remove semantic-tags-location-ring 0) nil nil)
     (signal (car err) (cdr err)))))

(defun semantic-pop-tag-mark ()
  "popup the tag save by semantic-goto-definition"
  (interactive)
  (if (ring-empty-p semantic-tags-location-ring)
      (message "%s" "No more tags available")
    (let* ((marker (ring-remove semantic-tags-location-ring 0))
           (buff (marker-buffer marker))
           (pos (marker-position marker)))
      (if (not buff)
          (message "Buffer has been deleted")
        (switch-to-buffer buff)
        (goto-char pos))
      (set-marker marker nil nil))))

(defun cedet-common-setup ()
  (local-set-key (kbd "C-c j") 'semantic-goto-definition)
  (local-set-key (kbd "C-c b") 'semantic-pop-tag-mark)
  (local-set-key (kbd "C-c o") 'semantic-ia-show-summary)
  (local-set-key (kbd "C-c d") 'semantic-ia-show-doc)
  (local-set-key (kbd "C-c p") 'semantic-analyze-proto-impl-toggle)

  (local-set-key (kbd "C-c f") 'semantic-symref)
  (local-set-key (kbd "C-c r") 'semantic-symref-symbol)

  (local-set-key (kbd "C-c <left>") 'semantic-tag-folding-fold-block)
  (local-set-key (kbd "C-c <right>") 'semantic-tag-folding-show-block)

  ;; We use auto complete to get candidate
  (if window-system
      (local-set-key (kbd "M-n") 'semantic-ia-complete-symbol-menu))

  (local-set-key (kbd "C-c m") 'eassist-list-methods))

(defun cedet-c-c++-setup ()
;;  (local-set-key "." 'semantic-complete-self-insert)
;;  (local-set-key ">" 'semantic-complete-self-insert)
(local-set-key (kbd "C-c h") 'eassist-switch-h-cpp) ; Jump between .c and .h
(when (executable-find "cscope")
  (require 'cedet-cscope)
  (require 'semantic/db-cscope)
  (semanticdb-enable-cscope-databases)
  (local-set-key (kbd "C-c i") 'cedet-cscope-create/update-database)))

(defun cedet-java-setup ()
  (require 'cedet-java)
  (require 'semantic/db-javap))

回答1:


The minor mode global-semantic-idle-breadcrumbs-mode is roughly similar to which-func-mode but uses the header instead of the mode line so it has more room to describe your context. There is also `global-semantic-stickyfunc-mode' which is also similar, but only shows what functions is partly off the top of the screen, not what the cursor is in.

To enable the original which-func-mode without disabling semantic, you may need to just disable the advice semantic uses for integration. Use ad-disable-advice for semantic-which to turn it off. The latest version of CEDET doesn't try to overload which-func so updating to the latest could work too.



来源:https://stackoverflow.com/questions/17119422/which-function-mode-cannot-work-with-official-cedet-2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!