;;; wisent-python.el --- Semantic support for Python
-;; Copyright (C) 2002, 2004, 2006-2012 Free Software Foundation, Inc.
+;; Copyright (C) 2002, 2004, 2006-2015 Free Software Foundation, Inc.
;; Author: Richard Kim <emacs18@gmail.com>
;; Maintainer: Richard Kim <emacs18@gmail.com>
(require 'semantic/find)
(require 'semantic/dep)
(require 'semantic/ctxt)
+(require 'semantic/format)
(eval-when-compile
(require 'cl))
(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
Return nil if there is nothing relevant."
nil)
+;;; Tag Formatting
+;;
+(define-mode-local-override semantic-format-tag-abbreviate python-mode (tag &optional parent color)
+ "Format an abbreviated tag for python.
+Shortens 'code' tags, but passes through for others."
+ (cond ((semantic-tag-of-class-p tag 'code)
+ ;; Just take the first line.
+ (let ((name (semantic-tag-name tag)))
+ (when (string-match "\n" name)
+ (setq name (substring name 0 (match-beginning 0))))
+ name))
+ (t
+ (semantic-format-tag-abbreviate-default tag parent color))))
+
;;; Enable Semantic in `python-mode'.
;;