From bf659b3f5819b9c3664c08fb01a7e51efff01fe4 Mon Sep 17 00:00:00 2001 From: David Engster Date: Sun, 14 Oct 2012 21:20:28 +0200 Subject: [PATCH] Merge changes from CEDET upstream. * semantic.el (semantic-error-if-unparsed): New function. Raise error if buffer was not parsed by Semantic (bug #12045). (navigate-menu, edit-menu, cedet-menu-map): Enable Semantic items only if buffer was parsed. Also, replace ':active' with ':enable' where necessary. * semantic/wisent/python.el (semantic-python-get-system-include-path): Use `python-shell-internal-send-string' if available to query Python for system paths. * semantic/senator.el (senator-next-tag): (senator-previous-tag): (senator-go-to-up-reference): Use `semantic-error-if-unparsed'. * semantic/complete.el (semantic-complete-jump-local): (semantic-complete-jump): (semantic-complete-jump-local-members): (semantic-complete-self-insert): Use `semantic-error-if-unparsed'. (semantic-complete-inline-project): Fix autoload cookie. * semantic/analyze/complete.el (semantic-analyze-possible-completions): Check if buffer was parsed. Only raise an error if function was called interactively, otherwise silently return nil. * cedet.el (cedet-menu-map): Fix copy&paste typo in menu creation. --- lisp/cedet/ChangeLog | 30 ++++++++++++++++++++ lisp/cedet/cedet.el | 2 +- lisp/cedet/semantic.el | 37 +++++++++++++++++++------ lisp/cedet/semantic/analyze/complete.el | 33 ++++++++++++---------- lisp/cedet/semantic/complete.el | 5 +++- lisp/cedet/semantic/senator.el | 3 ++ lisp/cedet/semantic/wisent/python.el | 27 ++++++------------ 7 files changed, 95 insertions(+), 42 deletions(-) diff --git a/lisp/cedet/ChangeLog b/lisp/cedet/ChangeLog index 0aeeeebc56..754bde475a 100644 --- a/lisp/cedet/ChangeLog +++ b/lisp/cedet/ChangeLog @@ -1,3 +1,33 @@ +2012-10-14 David Engster + + * semantic.el (semantic-error-if-unparsed): New function. Raise + error if buffer was not parsed by Semantic (bug #12045). + (navigate-menu, edit-menu, cedet-menu-map): Enable Semantic items + only if buffer was parsed. Also, replace ':active' with ':enable' + where necessary. + + * semantic/wisent/python.el + (semantic-python-get-system-include-path): Use + `python-shell-internal-send-string' if available to query Python + for system paths. + + * semantic/senator.el (senator-next-tag): + (senator-previous-tag): + (senator-go-to-up-reference): Use `semantic-error-if-unparsed'. + + * semantic/complete.el (semantic-complete-jump-local): + (semantic-complete-jump): + (semantic-complete-jump-local-members): + (semantic-complete-self-insert): Use `semantic-error-if-unparsed'. + (semantic-complete-inline-project): Fix autoload cookie. + + * semantic/analyze/complete.el + (semantic-analyze-possible-completions): Check if buffer was + parsed. Only raise an error if function was called interactively, + otherwise silently return nil. + + * cedet.el (cedet-menu-map): Fix copy&paste typo in menu creation. + 2012-10-07 David Engster * semantic/wisent/python.el (semantic-ctxt-current-function) diff --git a/lisp/cedet/cedet.el b/lisp/cedet/cedet.el index 5c21e4ab53..327a72f9dc 100644 --- a/lisp/cedet/cedet.el +++ b/lisp/cedet/cedet.el @@ -59,7 +59,7 @@ (define-key map [navigate-menu] 'undefined) (define-key map [semantic-options-separator] 'undefined) (define-key map [global-semantic-highlight-func-mode] 'undefined) - (define-key map [global-semantic-highlight-func-mode] 'undefined) + (define-key map [global-semantic-stickyfunc-mode] 'undefined) (define-key map [global-semantic-decoration-mode] 'undefined) (define-key map [global-semantic-idle-completions-mode] 'undefined) (define-key map [global-semantic-idle-summary-mode] 'undefined) diff --git a/lisp/cedet/semantic.el b/lisp/cedet/semantic.el index e02790cbfa..373864a43d 100644 --- a/lisp/cedet/semantic.el +++ b/lisp/cedet/semantic.el @@ -319,6 +319,11 @@ a parse of the buffer.") "Return non-nil if the current buffer was set up for parsing." semantic-new-buffer-fcn-was-run) +(defsubst semantic-error-if-unparsed () + "Raise an error if current buffer was not parsed by Semantic." + (unless semantic-new-buffer-fcn-was-run + (error "Buffer was not parsed by Semantic."))) + (defsubst semantic--umatched-syntax-needs-refresh-p () "Return non-nil if the unmatched syntax cache needs a refresh. That is, if it is dirty or if the current parse tree isn't up to date." @@ -907,75 +912,91 @@ Throw away all the old tags, and recreate the tag database." ;; Edit Tags submenu: (define-key edit-menu [semantic-analyze-possible-completions] '(menu-item "List Completions" semantic-analyze-possible-completions + :enable (semantic-active-p) :help "Display a list of completions for the tag at point")) (define-key edit-menu [semantic-complete-analyze-inline] '(menu-item "Complete Tag Inline" semantic-complete-analyze-inline + :enable (semantic-active-p) :help "Display inline completion for the tag at point")) (define-key edit-menu [semantic-completion-separator] '("--")) (define-key edit-menu [senator-transpose-tags-down] '(menu-item "Transpose Tags Down" senator-transpose-tags-down - :active (semantic-current-tag) + :enable (and (semantic-active-p) + (semantic-current-tag)) :help "Transpose the current tag and the next tag")) (define-key edit-menu [senator-transpose-tags-up] '(menu-item "Transpose Tags Up" senator-transpose-tags-up - :active (semantic-current-tag) + :enable (and (semantic-active-p) + (semantic-current-tag)) :help "Transpose the current tag and the previous tag")) (define-key edit-menu [semantic-edit-separator] '("--")) (define-key edit-menu [senator-yank-tag] '(menu-item "Yank Tag" senator-yank-tag - :active (not (ring-empty-p senator-tag-ring)) + :enable (not (ring-empty-p senator-tag-ring)) :help "Yank the head of the tag ring into the buffer")) (define-key edit-menu [senator-copy-tag-to-register] '(menu-item "Copy Tag To Register" senator-copy-tag-to-register - :active (semantic-current-tag) + :enable (and (semantic-active-p) + (semantic-current-tag)) :help "Yank the head of the tag ring into the buffer")) (define-key edit-menu [senator-copy-tag] '(menu-item "Copy Tag" senator-copy-tag - :active (semantic-current-tag) + :enable (and (semantic-active-p) + (semantic-current-tag)) :help "Copy the current tag to the tag ring")) (define-key edit-menu [senator-kill-tag] '(menu-item "Kill Tag" senator-kill-tag - :active (semantic-current-tag) + :enable (and (semantic-active-p) + (semantic-current-tag)) :help "Kill the current tag, and copy it to the tag ring")) ;; Navigate Tags submenu: (define-key navigate-menu [senator-narrow-to-defun] '(menu-item "Narrow to Tag" senator-narrow-to-defun - :active (semantic-current-tag) + :enable (and (semantic-active-p) + (semantic-current-tag)) :help "Narrow the buffer to the bounds of the current tag")) (define-key navigate-menu [semantic-narrow-to-defun-separator] '("--")) (define-key navigate-menu [semantic-symref-symbol] '(menu-item "Find Tag References..." semantic-symref-symbol + :enable (semantic-active-p) :help "Read a tag and list the references to it")) (define-key navigate-menu [semantic-complete-jump] '(menu-item "Find Tag Globally..." semantic-complete-jump + :enable (semantic-active-p) :help "Read a tag name and find it in the current project")) (define-key navigate-menu [semantic-complete-jump-local-members] '(menu-item "Find Local Members ..." semantic-complete-jump-local-members + :enable (semantic-active-p) :help "Read a tag name and find a local member with that name")) (define-key navigate-menu [semantic-complete-jump-local] '(menu-item "Find Tag in This Buffer..." semantic-complete-jump-local + :enable (semantic-active-p) :help "Read a tag name and find it in this buffer")) (define-key navigate-menu [semantic-navigation-separator] '("--")) (define-key navigate-menu [senator-go-to-up-reference] '(menu-item "Parent Tag" senator-go-to-up-reference + :enable (semantic-active-p) :help "Navigate up one reference by tag")) (define-key navigate-menu [senator-next-tag] '(menu-item "Next Tag" senator-next-tag + :enable (semantic-active-p) :help "Go to the next tag")) (define-key navigate-menu [senator-previous-tag] '(menu-item "Previous Tag" senator-previous-tag + :enable (semantic-active-p) :help "Go to the previous tag")) ;; Top level menu items: (define-key cedet-menu-map [semantic-force-refresh] '(menu-item "Reparse Buffer" semantic-force-refresh :help "Force a full reparse of the current buffer" - :visible semantic-mode)) + :visible semantic-mode + :enable (semantic-active-p))) (define-key cedet-menu-map [semantic-edit-menu] `(menu-item "Edit Tags" ,edit-menu :visible semantic-mode)) diff --git a/lisp/cedet/semantic/analyze/complete.el b/lisp/cedet/semantic/analyze/complete.el index edc3cdc230..bb9bbf6352 100644 --- a/lisp/cedet/semantic/analyze/complete.el +++ b/lisp/cedet/semantic/analyze/complete.el @@ -87,20 +87,25 @@ in a buffer." ;; In theory, we don't need the below since the context will ;; do it for us. ;;(semantic-refresh-tags-safe) - (with-syntax-table semantic-lex-syntax-table - (let* ((context (if (semantic-analyze-context-child-p context) - context - (semantic-analyze-current-context context))) - (ans (if (not context) - (error "Nothing to complete") - (:override)))) - ;; If interactive, display them. - (when (called-interactively-p 'any) - (with-output-to-temp-buffer "*Possible Completions*" - (semantic-analyze-princ-sequence ans "" (current-buffer))) - (shrink-window-if-larger-than-buffer - (get-buffer-window "*Possible Completions*"))) - ans))) + (if (semantic-active-p) + (with-syntax-table semantic-lex-syntax-table + (let* ((context (if (semantic-analyze-context-child-p context) + context + (semantic-analyze-current-context context))) + (ans (if (not context) + (error "Nothing to complete") + (:override)))) + ;; If interactive, display them. + (when (called-interactively-p 'any) + (with-output-to-temp-buffer "*Possible Completions*" + (semantic-analyze-princ-sequence ans "" (current-buffer))) + (shrink-window-if-larger-than-buffer + (get-buffer-window "*Possible Completions*"))) + ans)) + ;; Buffer was not parsed by Semantic. + ;; Raise error if called interactively. + (when (cedet-called-interactively-p 'any) + (error "Buffer was not parsed by Semantic.")))) (defun semantic-analyze-possible-completions-default (context &optional flags) "Default method for producing smart completions. diff --git a/lisp/cedet/semantic/complete.el b/lisp/cedet/semantic/complete.el index 9c2da9faef..59d17f2f8b 100644 --- a/lisp/cedet/semantic/complete.el +++ b/lisp/cedet/semantic/complete.el @@ -2088,6 +2088,7 @@ completion works." (defun semantic-complete-jump-local () "Jump to a local semantic symbol." (interactive) + (semantic-error-if-unparsed) (let ((tag (semantic-complete-read-tag-buffer-deep "Jump to symbol: "))) (when (semantic-tag-p tag) (push-mark) @@ -2101,6 +2102,7 @@ completion works." (defun semantic-complete-jump () "Jump to a semantic symbol." (interactive) + (semantic-error-if-unparsed) (let* ((tag (semantic-complete-read-tag-project "Jump to symbol: "))) (when (semantic-tag-p tag) (push-mark) @@ -2115,6 +2117,7 @@ completion works." (defun semantic-complete-jump-local-members () "Jump to a semantic symbol." (interactive) + (semantic-error-if-unparsed) (let* ((tag (semantic-complete-read-tag-local-members "Jump to symbol: "))) (when (semantic-tag-p tag) (let ((start (condition-case nil (semantic-tag-start tag) @@ -2216,7 +2219,7 @@ use `semantic-complete-analyze-inline' to complete." (error nil)) )) -;;;;###autoload +;;;###autoload (defun semantic-complete-inline-project () "Perform inline completion for any symbol in the current project. `semantic-analyze-possible-completions' is used to determine the diff --git a/lisp/cedet/semantic/senator.el b/lisp/cedet/semantic/senator.el index 64f99a8ad6..1138c13096 100644 --- a/lisp/cedet/semantic/senator.el +++ b/lisp/cedet/semantic/senator.el @@ -255,6 +255,7 @@ TEXT, BOUND, NOERROR, and COUNT arguments are interpreted." "Navigate to the next Semantic tag. Return the tag or nil if at end of buffer." (interactive) + (semantic-error-if-unparsed) (let ((pos (point)) (tag (semantic-current-tag)) where) @@ -294,6 +295,7 @@ Return the tag or nil if at end of buffer." "Navigate to the previous Semantic tag. Return the tag or nil if at beginning of buffer." (interactive) + (semantic-error-if-unparsed) (let ((pos (point)) (tag (semantic-current-tag)) where) @@ -519,6 +521,7 @@ If that parent which is only a reference in the function tag is found, we can jump to it. Some tags such as includes have other reference features." (interactive) + (semantic-error-if-unparsed) (let ((result (semantic-up-reference (or tag (semantic-current-tag))))) (if (not result) (error "No up reference found") diff --git a/lisp/cedet/semantic/wisent/python.el b/lisp/cedet/semantic/wisent/python.el index a0ea488f0f..89c0499b7d 100644 --- a/lisp/cedet/semantic/wisent/python.el +++ b/lisp/cedet/semantic/wisent/python.el @@ -48,24 +48,15 @@ (defun semantic-python-get-system-include-path () "Evaluate some Python code that determines the system include path." - (python-proc) - (if python-buffer - (with-current-buffer python-buffer - (set (make-local-variable 'python-preoutput-result) nil) - (python-send-string - "import sys; print '_emacs_out ' + '\\0'.join(sys.path)") - (accept-process-output (python-proc) 2) - (if python-preoutput-result - (split-string python-preoutput-result "[\0\n]" t) - ;; Try a second, Python3k compatible shot - (python-send-string - "import sys; print('_emacs_out ' + '\\0'.join(sys.path))") - (accept-process-output (python-proc) 2) - (if python-preoutput-result - (split-string python-preoutput-result "[\0\n]" t) - (message "Timeout while querying Python for system include path.") - nil))) - (message "Python seems to be unavailable on this system."))) + (delq nil + (mapcar + (lambda (dir) + (when (file-directory-p dir) + dir)) + (split-string + (python-shell-internal-send-string + "import sys;print ('\\n'.join(sys.path))") + "\n" t)))) (defcustom-mode-local-semantic-dependency-system-include-path python-mode semantic-python-dependency-system-include-path -- 2.20.1