2010-01-09 19:38:07 -05:00
|
|
|
|
;;; wisent-python.el --- Semantic support for Python
|
|
|
|
|
|
2018-01-01 00:21:42 -08:00
|
|
|
|
;; Copyright (C) 2002, 2004, 2006-2018 Free Software Foundation, Inc.
|
2010-01-09 19:38:07 -05:00
|
|
|
|
|
|
|
|
|
;; Author: Richard Kim <emacs18@gmail.com>
|
|
|
|
|
;; Maintainer: Richard Kim <emacs18@gmail.com>
|
|
|
|
|
;; Created: June 2002
|
|
|
|
|
;; Keywords: syntax
|
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs 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 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
;; GNU Emacs 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
|
2017-09-13 15:52:52 -07:00
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2010-01-09 19:38:07 -05:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
;;
|
|
|
|
|
;; Parser support for Python.
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
2012-10-02 02:10:29 +08:00
|
|
|
|
(require 'rx)
|
|
|
|
|
|
|
|
|
|
;; Try to load python support, but fail silently since it is only used
|
|
|
|
|
;; for optional functionality
|
|
|
|
|
(require 'python nil t)
|
|
|
|
|
|
2010-01-09 19:38:07 -05:00
|
|
|
|
(require 'semantic/wisent)
|
|
|
|
|
(require 'semantic/wisent/python-wy)
|
2012-10-02 02:10:29 +08:00
|
|
|
|
(require 'semantic/find)
|
2010-01-09 19:38:07 -05:00
|
|
|
|
(require 'semantic/dep)
|
|
|
|
|
(require 'semantic/ctxt)
|
2013-07-29 22:26:19 +02:00
|
|
|
|
(require 'semantic/format)
|
2010-01-09 19:38:07 -05:00
|
|
|
|
|
2012-10-02 02:10:29 +08:00
|
|
|
|
(eval-when-compile
|
|
|
|
|
(require 'cl))
|
|
|
|
|
|
|
|
|
|
;;; Customization
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
(defun semantic-python-get-system-include-path ()
|
|
|
|
|
"Evaluate some Python code that determines the system include path."
|
2012-10-14 21:20:28 +02:00
|
|
|
|
(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))))
|
2012-10-02 02:10:29 +08:00
|
|
|
|
|
|
|
|
|
(defcustom-mode-local-semantic-dependency-system-include-path
|
|
|
|
|
python-mode semantic-python-dependency-system-include-path
|
|
|
|
|
(when (and (featurep 'python)
|
|
|
|
|
;; python-mode and batch somehow often hangs.
|
|
|
|
|
(not noninteractive))
|
|
|
|
|
(semantic-python-get-system-include-path))
|
|
|
|
|
"The system include path used by Python language.")
|
2010-01-09 19:38:07 -05:00
|
|
|
|
|
|
|
|
|
;;; Lexical analysis
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
;; Python strings are delimited by either single quotes or double
|
2012-10-02 02:10:29 +08:00
|
|
|
|
;; quotes, e.g., "I'm a string" and 'I too am a string'.
|
2010-01-09 19:38:07 -05:00
|
|
|
|
;; In addition a string can have either a 'r' and/or 'u' prefix.
|
|
|
|
|
;; The 'r' prefix means raw, i.e., normal backslash substitutions are
|
|
|
|
|
;; to be suppressed. For example, r"01\n34" is a string with six
|
|
|
|
|
;; characters 0, 1, \, n, 3 and 4. The 'u' prefix means the following
|
2011-11-20 20:35:27 +01:00
|
|
|
|
;; string is Unicode.
|
2012-10-02 02:10:29 +08:00
|
|
|
|
(defconst wisent-python-string-start-re "[uU]?[rR]?['\"]"
|
Fix typos in CEDET docstrings.
* cedet/semantic/analyze.el (semantic-analyze-push-error)
(semantic-analyze-context, semantic-analyze-context-assignment)
(semantic-analyze-find-tag-sequence, semantic-analyze-find-tag):
* cedet/semantic/java.el (java-mode, semantic-tag-include-filename)
(semantic-java-doc-keywords-map):
* cedet/semantic/bovine/c.el (c-mode, semantic-c-member-of-autocast)
(semantic-lex-c-nested-namespace-ignore-second, semantic-parse-region)
(semantic-c-parse-lexical-token, semantic-c-debug-mode-init-pch)
(semantic-c-classname, semantic-format-tag-uml-prototype)
(semantic-c-dereference-namespace, semantic-analyze-type-constants):
* cedet/semantic/bovine/el.el (semantic-elisp-form-to-doc-string)
(semantic-emacs-lisp-obsoleted-doc, semantic-up-context)
(semantic-get-local-variables, semantic-end-of-command)
(semantic-beginning-of-command, semantic-ctxt-current-class-list)
(lisp-mode):
* cedet/semantic/bovine/make.el (makefile-mode):
* cedet/semantic/wisent/python.el (wisent-python-string-re)
(wisent-python-implicit-line-joining-p, wisent-python-forward-string)
(wisent-python-lex-beginning-of-line, wisent-python-lex-end-of-line)
(semantic-lex, semantic-get-local-variables, python-mode):
* cedet/semantic/wisent/python-wy.el (wisent-python-wy--keyword-table):
* cedet/srecode/extract.el (srecode-extract-state-set)
(srecode-extract-method): Fix typos in docstrings.
2010-01-12 05:51:26 +01:00
|
|
|
|
"Regexp matching beginning of a Python string.")
|
2010-01-09 19:38:07 -05:00
|
|
|
|
|
2012-10-02 02:10:29 +08:00
|
|
|
|
(defconst wisent-python-string-re
|
|
|
|
|
(rx
|
|
|
|
|
(opt (any "uU")) (opt (any "rR"))
|
|
|
|
|
(or
|
|
|
|
|
;; Triple-quoted string using apostrophes
|
|
|
|
|
(: "'''" (zero-or-more (or "\\'"
|
|
|
|
|
(not (any "'"))
|
|
|
|
|
(: (repeat 1 2 "'") (not (any "'")))))
|
|
|
|
|
"'''")
|
|
|
|
|
;; String using apostrophes
|
|
|
|
|
(: "'" (zero-or-more (or "\\'"
|
|
|
|
|
(not (any "'"))))
|
|
|
|
|
"'")
|
|
|
|
|
;; Triple-quoted string using quotation marks.
|
|
|
|
|
(: "\"\"\"" (zero-or-more (or "\\\""
|
|
|
|
|
(not (any "\""))
|
|
|
|
|
(: (repeat 1 2 "\"") (not (any "\"")))))
|
|
|
|
|
"\"\"\"")
|
|
|
|
|
;; String using quotation marks.
|
|
|
|
|
(: "\"" (zero-or-more (or "\\\""
|
|
|
|
|
(not (any "\""))))
|
|
|
|
|
"\"")))
|
|
|
|
|
"Regexp matching a complete Python string.")
|
|
|
|
|
|
2010-01-09 19:38:07 -05:00
|
|
|
|
(defvar wisent-python-EXPANDING-block nil
|
|
|
|
|
"Non-nil when expanding a paren block for Python lexical analyzer.")
|
|
|
|
|
|
|
|
|
|
(defun wisent-python-implicit-line-joining-p ()
|
|
|
|
|
"Return non-nil if implicit line joining is active.
|
Fix typos in CEDET docstrings.
* cedet/semantic/analyze.el (semantic-analyze-push-error)
(semantic-analyze-context, semantic-analyze-context-assignment)
(semantic-analyze-find-tag-sequence, semantic-analyze-find-tag):
* cedet/semantic/java.el (java-mode, semantic-tag-include-filename)
(semantic-java-doc-keywords-map):
* cedet/semantic/bovine/c.el (c-mode, semantic-c-member-of-autocast)
(semantic-lex-c-nested-namespace-ignore-second, semantic-parse-region)
(semantic-c-parse-lexical-token, semantic-c-debug-mode-init-pch)
(semantic-c-classname, semantic-format-tag-uml-prototype)
(semantic-c-dereference-namespace, semantic-analyze-type-constants):
* cedet/semantic/bovine/el.el (semantic-elisp-form-to-doc-string)
(semantic-emacs-lisp-obsoleted-doc, semantic-up-context)
(semantic-get-local-variables, semantic-end-of-command)
(semantic-beginning-of-command, semantic-ctxt-current-class-list)
(lisp-mode):
* cedet/semantic/bovine/make.el (makefile-mode):
* cedet/semantic/wisent/python.el (wisent-python-string-re)
(wisent-python-implicit-line-joining-p, wisent-python-forward-string)
(wisent-python-lex-beginning-of-line, wisent-python-lex-end-of-line)
(semantic-lex, semantic-get-local-variables, python-mode):
* cedet/semantic/wisent/python-wy.el (wisent-python-wy--keyword-table):
* cedet/srecode/extract.el (srecode-extract-state-set)
(srecode-extract-method): Fix typos in docstrings.
2010-01-12 05:51:26 +01:00
|
|
|
|
That is, if inside an expression in parentheses, square brackets or
|
2010-01-09 19:38:07 -05:00
|
|
|
|
curly braces."
|
|
|
|
|
wisent-python-EXPANDING-block)
|
|
|
|
|
|
|
|
|
|
(defsubst wisent-python-forward-string ()
|
Fix typos in CEDET docstrings.
* cedet/semantic/analyze.el (semantic-analyze-push-error)
(semantic-analyze-context, semantic-analyze-context-assignment)
(semantic-analyze-find-tag-sequence, semantic-analyze-find-tag):
* cedet/semantic/java.el (java-mode, semantic-tag-include-filename)
(semantic-java-doc-keywords-map):
* cedet/semantic/bovine/c.el (c-mode, semantic-c-member-of-autocast)
(semantic-lex-c-nested-namespace-ignore-second, semantic-parse-region)
(semantic-c-parse-lexical-token, semantic-c-debug-mode-init-pch)
(semantic-c-classname, semantic-format-tag-uml-prototype)
(semantic-c-dereference-namespace, semantic-analyze-type-constants):
* cedet/semantic/bovine/el.el (semantic-elisp-form-to-doc-string)
(semantic-emacs-lisp-obsoleted-doc, semantic-up-context)
(semantic-get-local-variables, semantic-end-of-command)
(semantic-beginning-of-command, semantic-ctxt-current-class-list)
(lisp-mode):
* cedet/semantic/bovine/make.el (makefile-mode):
* cedet/semantic/wisent/python.el (wisent-python-string-re)
(wisent-python-implicit-line-joining-p, wisent-python-forward-string)
(wisent-python-lex-beginning-of-line, wisent-python-lex-end-of-line)
(semantic-lex, semantic-get-local-variables, python-mode):
* cedet/semantic/wisent/python-wy.el (wisent-python-wy--keyword-table):
* cedet/srecode/extract.el (srecode-extract-state-set)
(srecode-extract-method): Fix typos in docstrings.
2010-01-12 05:51:26 +01:00
|
|
|
|
"Move point at the end of the Python string at point."
|
2012-10-02 02:10:29 +08:00
|
|
|
|
(if (looking-at wisent-python-string-re)
|
|
|
|
|
(let ((start (match-beginning 0))
|
|
|
|
|
(end (match-end 0)))
|
|
|
|
|
;; Incomplete triple-quoted string gets matched instead as a
|
|
|
|
|
;; complete single quoted string. (This special case would be
|
|
|
|
|
;; unnecessary if Emacs regular expressions had negative
|
|
|
|
|
;; look-ahead assertions.)
|
|
|
|
|
(when (and (= (- end start) 2)
|
|
|
|
|
(looking-at "\"\\{3\\}\\|'\\{3\\}"))
|
|
|
|
|
(error "unterminated syntax"))
|
|
|
|
|
(goto-char end))
|
|
|
|
|
(error "unterminated syntax")))
|
|
|
|
|
|
|
|
|
|
(defun wisent-python-forward-balanced-expression ()
|
|
|
|
|
"Move point to the end of the balanced expression at point.
|
Prefer directed to neutral quotes
Prefer directed to neutral quotes in docstings and diagnostics.
In docstrings, escape apostrophes that would otherwise be translated
to curved quotes using the newer, simpler rules.
* admin/unidata/unidata-gen.el (unidata-gen-table):
* lisp/align.el (align-region):
* lisp/allout.el (allout-mode, allout-solicit-alternate-bullet):
* lisp/bookmark.el (bookmark-default-annotation-text):
* lisp/calc/calc-aent.el (math-read-if, math-read-factor):
* lisp/calc/calc-lang.el (math-read-giac-subscr)
(math-read-math-subscr):
* lisp/calc/calc-misc.el (report-calc-bug):
* lisp/calc/calc-prog.el (calc-fix-token-name)
(calc-read-parse-table-part):
* lisp/cedet/ede/pmake.el (ede-proj-makefile-insert-dist-rules):
* lisp/cedet/semantic/complete.el (semantic-displayor-show-request):
* lisp/dabbrev.el (dabbrev-expand):
* lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine):
* lisp/emacs-lisp/elint.el (elint-get-top-forms):
* lisp/emacs-lisp/lisp-mnt.el (lm-verify):
* lisp/emulation/viper-cmd.el (viper-toggle-search-style):
* lisp/erc/erc-button.el (erc-nick-popup):
* lisp/erc/erc.el (erc-cmd-LOAD, erc-handle-login):
* lisp/eshell/em-dirs.el (eshell/cd):
* lisp/eshell/em-glob.el (eshell-glob-regexp):
* lisp/eshell/em-pred.el (eshell-parse-modifiers):
* lisp/eshell/esh-arg.el (eshell-parse-arguments):
* lisp/eshell/esh-opt.el (eshell-show-usage):
* lisp/files-x.el (modify-file-local-variable):
* lisp/filesets.el (filesets-add-buffer, filesets-remove-buffer)
(filesets-update-pre010505):
* lisp/find-cmd.el (find-generic, find-to-string):
* lisp/gnus/auth-source.el (auth-source-netrc-parse-entries):
* lisp/gnus/gnus-agent.el (gnus-agent-check-overview-buffer)
(gnus-agent-fetch-headers):
* lisp/gnus/gnus-int.el (gnus-start-news-server):
* lisp/gnus/gnus-registry.el:
(gnus-registry--split-fancy-with-parent-internal):
* lisp/gnus/gnus-score.el (gnus-summary-increase-score):
* lisp/gnus/gnus-start.el (gnus-convert-old-newsrc):
* lisp/gnus/gnus-topic.el (gnus-topic-rename):
* lisp/gnus/legacy-gnus-agent.el (gnus-agent-unlist-expire-days):
* lisp/gnus/nnmairix.el (nnmairix-widget-create-query):
* lisp/gnus/spam.el (spam-check-blackholes):
* lisp/mail/feedmail.el (feedmail-run-the-queue):
* lisp/mpc.el (mpc-playlist-rename):
* lisp/net/ange-ftp.el (ange-ftp-shell-command):
* lisp/net/mairix.el (mairix-widget-create-query):
* lisp/net/tramp-cache.el:
* lisp/obsolete/otodo-mode.el (todo-more-important-p):
* lisp/obsolete/pgg-gpg.el (pgg-gpg-process-region):
* lisp/obsolete/pgg-pgp.el (pgg-pgp-process-region):
* lisp/obsolete/pgg-pgp5.el (pgg-pgp5-process-region):
* lisp/org/ob-core.el (org-babel-goto-named-src-block)
(org-babel-goto-named-result):
* lisp/org/ob-fortran.el (org-babel-fortran-ensure-main-wrap):
* lisp/org/ob-ref.el (org-babel-ref-resolve):
* lisp/org/org-agenda.el (org-agenda-prepare):
* lisp/org/org-bibtex.el (org-bibtex-fields):
* lisp/org/org-clock.el (org-clock-notify-once-if-expired)
(org-clock-resolve):
* lisp/org/org-feed.el (org-feed-parse-atom-entry):
* lisp/org/org-habit.el (org-habit-parse-todo):
* lisp/org/org-mouse.el (org-mouse-popup-global-menu)
(org-mouse-context-menu):
* lisp/org/org-table.el (org-table-edit-formulas):
* lisp/org/ox.el (org-export-async-start):
* lisp/play/dunnet.el (dun-score, dun-help, dun-endgame-question)
(dun-rooms, dun-endgame-questions):
* lisp/progmodes/ada-mode.el (ada-goto-matching-start):
* lisp/progmodes/ada-xref.el (ada-find-executable):
* lisp/progmodes/antlr-mode.el (antlr-options-alists):
* lisp/progmodes/flymake.el (flymake-parse-err-lines)
(flymake-start-syntax-check-process):
* lisp/progmodes/python.el (python-define-auxiliary-skeleton):
* lisp/progmodes/sql.el (sql-comint):
* lisp/progmodes/verilog-mode.el (verilog-load-file-at-point):
* lisp/server.el (server-get-auth-key):
* lisp/subr.el (version-to-list):
* lisp/textmodes/reftex-ref.el (reftex-label):
* lisp/textmodes/reftex-toc.el (reftex-toc-rename-label):
* lisp/vc/ediff-diff.el (ediff-same-contents):
* lisp/vc/vc-cvs.el (vc-cvs-mode-line-string):
* test/automated/tramp-tests.el (tramp-test33-asynchronous-requests):
Use directed rather than neutral quotes in diagnostics.
2015-08-24 23:39:33 -07:00
|
|
|
|
Here “balanced expression” means anything matched by Emacs's
|
2012-10-02 02:10:29 +08:00
|
|
|
|
open/close parenthesis syntax classes. We can't use forward-sexp
|
|
|
|
|
for this because that Emacs built-in can't parse Python's
|
|
|
|
|
triple-quoted string syntax."
|
|
|
|
|
(let ((end-char (cdr (syntax-after (point)))))
|
|
|
|
|
(forward-char 1)
|
|
|
|
|
(while (not (or (eobp) (eq (char-after (point)) end-char)))
|
|
|
|
|
(cond
|
|
|
|
|
;; Skip over python strings.
|
|
|
|
|
((looking-at wisent-python-string-start-re)
|
|
|
|
|
(wisent-python-forward-string))
|
|
|
|
|
;; At a comment start just goto end of line.
|
|
|
|
|
((looking-at "\\s<")
|
|
|
|
|
(end-of-line))
|
|
|
|
|
;; Skip over balanced expressions.
|
|
|
|
|
((looking-at "\\s(")
|
|
|
|
|
(wisent-python-forward-balanced-expression))
|
|
|
|
|
;; Skip over white space, word, symbol, punctuation, paired
|
|
|
|
|
;; delimiter (backquote) characters, line continuation, and end
|
|
|
|
|
;; of comment characters (AKA newline characters in Python).
|
|
|
|
|
((zerop (skip-syntax-forward "-w_.$\\>"))
|
|
|
|
|
(error "can't figure out how to go forward from here"))))
|
|
|
|
|
;; Skip closing character. As a last resort this should raise an
|
|
|
|
|
;; error if we hit EOB before we find our closing character..
|
|
|
|
|
(forward-char 1)))
|
2010-01-09 19:38:07 -05:00
|
|
|
|
|
|
|
|
|
(defun wisent-python-forward-line ()
|
|
|
|
|
"Move point to the beginning of the next logical line.
|
|
|
|
|
Usually this is simply the next physical line unless strings,
|
|
|
|
|
implicit/explicit line continuation, blank lines, or comment lines are
|
|
|
|
|
encountered. This function skips over such items so that the point is
|
|
|
|
|
at the beginning of the next logical line. If the current logical
|
|
|
|
|
line ends at the end of the buffer, leave the point there."
|
|
|
|
|
(while (not (eolp))
|
|
|
|
|
(when (= (point)
|
|
|
|
|
(progn
|
|
|
|
|
(cond
|
|
|
|
|
;; Skip over python strings.
|
2012-10-02 02:10:29 +08:00
|
|
|
|
((looking-at wisent-python-string-start-re)
|
2010-01-09 19:38:07 -05:00
|
|
|
|
(wisent-python-forward-string))
|
|
|
|
|
;; At a comment start just goto end of line.
|
|
|
|
|
((looking-at "\\s<")
|
|
|
|
|
(end-of-line))
|
2012-10-02 02:10:29 +08:00
|
|
|
|
;; Skip over balanced expressions.
|
|
|
|
|
((looking-at "\\s(")
|
|
|
|
|
(wisent-python-forward-balanced-expression))
|
2010-01-09 19:38:07 -05:00
|
|
|
|
;; At the explicit line continuation character
|
|
|
|
|
;; (backslash) move to next line.
|
|
|
|
|
((looking-at "\\s\\")
|
|
|
|
|
(forward-line 1))
|
|
|
|
|
;; Skip over white space, word, symbol, punctuation,
|
|
|
|
|
;; and paired delimiter (backquote) characters.
|
|
|
|
|
((skip-syntax-forward "-w_.$)")))
|
|
|
|
|
(point)))
|
|
|
|
|
(error "python-forward-line endless loop detected")))
|
|
|
|
|
;; The point is at eol, skip blank and comment lines.
|
|
|
|
|
(forward-comment (point-max))
|
|
|
|
|
;; Goto the beginning of the next line.
|
|
|
|
|
(or (eobp) (beginning-of-line)))
|
|
|
|
|
|
|
|
|
|
(defun wisent-python-forward-line-skip-indented ()
|
|
|
|
|
"Move point to the next logical line, skipping indented lines.
|
2012-10-02 02:10:29 +08:00
|
|
|
|
That is the next line whose indentation is less than or equal to
|
|
|
|
|
the indentation of the current line."
|
2010-01-09 19:38:07 -05:00
|
|
|
|
(let ((indent (current-indentation)))
|
|
|
|
|
(while (progn (wisent-python-forward-line)
|
|
|
|
|
(and (not (eobp))
|
|
|
|
|
(> (current-indentation) indent))))))
|
|
|
|
|
|
|
|
|
|
(defun wisent-python-end-of-block ()
|
|
|
|
|
"Move point to the end of the current block."
|
|
|
|
|
(let ((indent (current-indentation)))
|
|
|
|
|
(while (and (not (eobp)) (>= (current-indentation) indent))
|
|
|
|
|
(wisent-python-forward-line-skip-indented))
|
|
|
|
|
;; Don't include final comments in current block bounds
|
|
|
|
|
(forward-comment (- (point-max)))
|
|
|
|
|
(or (bolp) (forward-line 1))
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
;; Indentation stack, what the Python (2.3) language spec. says:
|
|
|
|
|
;;
|
|
|
|
|
;; The indentation levels of consecutive lines are used to generate
|
|
|
|
|
;; INDENT and DEDENT tokens, using a stack, as follows.
|
|
|
|
|
;;
|
|
|
|
|
;; Before the first line of the file is read, a single zero is pushed
|
|
|
|
|
;; on the stack; this will never be popped off again. The numbers
|
|
|
|
|
;; pushed on the stack will always be strictly increasing from bottom
|
|
|
|
|
;; to top. At the beginning of each logical line, the line's
|
|
|
|
|
;; indentation level is compared to the top of the stack. If it is
|
|
|
|
|
;; equal, nothing happens. If it is larger, it is pushed on the stack,
|
|
|
|
|
;; and one INDENT token is generated. If it is smaller, it must be one
|
|
|
|
|
;; of the numbers occurring on the stack; all numbers on the stack
|
|
|
|
|
;; that are larger are popped off, and for each number popped off a
|
|
|
|
|
;; DEDENT token is generated. At the end of the file, a DEDENT token
|
|
|
|
|
;; is generated for each number remaining on the stack that is larger
|
|
|
|
|
;; than zero.
|
|
|
|
|
(defvar wisent-python-indent-stack)
|
|
|
|
|
|
|
|
|
|
(define-lex-analyzer wisent-python-lex-beginning-of-line
|
Fix typos in CEDET docstrings.
* cedet/semantic/analyze.el (semantic-analyze-push-error)
(semantic-analyze-context, semantic-analyze-context-assignment)
(semantic-analyze-find-tag-sequence, semantic-analyze-find-tag):
* cedet/semantic/java.el (java-mode, semantic-tag-include-filename)
(semantic-java-doc-keywords-map):
* cedet/semantic/bovine/c.el (c-mode, semantic-c-member-of-autocast)
(semantic-lex-c-nested-namespace-ignore-second, semantic-parse-region)
(semantic-c-parse-lexical-token, semantic-c-debug-mode-init-pch)
(semantic-c-classname, semantic-format-tag-uml-prototype)
(semantic-c-dereference-namespace, semantic-analyze-type-constants):
* cedet/semantic/bovine/el.el (semantic-elisp-form-to-doc-string)
(semantic-emacs-lisp-obsoleted-doc, semantic-up-context)
(semantic-get-local-variables, semantic-end-of-command)
(semantic-beginning-of-command, semantic-ctxt-current-class-list)
(lisp-mode):
* cedet/semantic/bovine/make.el (makefile-mode):
* cedet/semantic/wisent/python.el (wisent-python-string-re)
(wisent-python-implicit-line-joining-p, wisent-python-forward-string)
(wisent-python-lex-beginning-of-line, wisent-python-lex-end-of-line)
(semantic-lex, semantic-get-local-variables, python-mode):
* cedet/semantic/wisent/python-wy.el (wisent-python-wy--keyword-table):
* cedet/srecode/extract.el (srecode-extract-state-set)
(srecode-extract-method): Fix typos in docstrings.
2010-01-12 05:51:26 +01:00
|
|
|
|
"Detect and create Python indentation tokens at beginning of line."
|
2010-01-09 19:38:07 -05:00
|
|
|
|
(and
|
|
|
|
|
(bolp) (not (wisent-python-implicit-line-joining-p))
|
|
|
|
|
(let ((last-indent (car wisent-python-indent-stack))
|
|
|
|
|
(last-pos (point))
|
|
|
|
|
(curr-indent (current-indentation)))
|
|
|
|
|
(skip-syntax-forward "-")
|
|
|
|
|
(cond
|
|
|
|
|
;; Skip comments and blank lines. No change in indentation.
|
|
|
|
|
((or (eolp) (looking-at semantic-lex-comment-regex))
|
|
|
|
|
(forward-comment (point-max))
|
|
|
|
|
(or (eobp) (beginning-of-line))
|
|
|
|
|
(setq semantic-lex-end-point (point))
|
|
|
|
|
;; Loop lexer to handle the next line.
|
|
|
|
|
t)
|
|
|
|
|
;; No change in indentation.
|
|
|
|
|
((= curr-indent last-indent)
|
|
|
|
|
(setq semantic-lex-end-point (point))
|
|
|
|
|
;; Try next analyzers.
|
|
|
|
|
nil)
|
|
|
|
|
;; Indentation increased
|
|
|
|
|
((> curr-indent last-indent)
|
|
|
|
|
(if (or (not semantic-lex-maximum-depth)
|
|
|
|
|
(< semantic-lex-current-depth semantic-lex-maximum-depth))
|
|
|
|
|
(progn
|
|
|
|
|
;; Return an INDENT lexical token
|
|
|
|
|
(setq semantic-lex-current-depth (1+ semantic-lex-current-depth))
|
|
|
|
|
(push curr-indent wisent-python-indent-stack)
|
|
|
|
|
(semantic-lex-push-token
|
|
|
|
|
(semantic-lex-token 'INDENT last-pos (point))))
|
|
|
|
|
;; Add an INDENT_BLOCK token
|
|
|
|
|
(semantic-lex-push-token
|
|
|
|
|
(semantic-lex-token
|
|
|
|
|
'INDENT_BLOCK
|
|
|
|
|
(progn (beginning-of-line) (point))
|
|
|
|
|
(semantic-lex-unterminated-syntax-protection 'INDENT_BLOCK
|
|
|
|
|
(wisent-python-end-of-block)
|
|
|
|
|
(point)))))
|
|
|
|
|
;; Loop lexer to handle tokens in current line.
|
|
|
|
|
t)
|
|
|
|
|
;; Indentation decreased
|
2012-10-02 02:10:29 +08:00
|
|
|
|
((progn
|
|
|
|
|
;; Pop items from indentation stack
|
|
|
|
|
(while (< curr-indent last-indent)
|
|
|
|
|
(pop wisent-python-indent-stack)
|
|
|
|
|
(setq semantic-lex-current-depth (1- semantic-lex-current-depth)
|
|
|
|
|
last-indent (car wisent-python-indent-stack))
|
|
|
|
|
(semantic-lex-push-token
|
|
|
|
|
(semantic-lex-token 'DEDENT last-pos (point))))
|
|
|
|
|
(= last-pos (point)))
|
2010-01-09 19:38:07 -05:00
|
|
|
|
;; If pos did not change, then we must return nil so that
|
|
|
|
|
;; other lexical analyzers can be run.
|
2012-10-02 02:10:29 +08:00
|
|
|
|
nil))))
|
2010-01-09 19:38:07 -05:00
|
|
|
|
;; All the work was done in the above analyzer matching condition.
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
(define-lex-regex-analyzer wisent-python-lex-end-of-line
|
Fix typos in CEDET docstrings.
* cedet/semantic/analyze.el (semantic-analyze-push-error)
(semantic-analyze-context, semantic-analyze-context-assignment)
(semantic-analyze-find-tag-sequence, semantic-analyze-find-tag):
* cedet/semantic/java.el (java-mode, semantic-tag-include-filename)
(semantic-java-doc-keywords-map):
* cedet/semantic/bovine/c.el (c-mode, semantic-c-member-of-autocast)
(semantic-lex-c-nested-namespace-ignore-second, semantic-parse-region)
(semantic-c-parse-lexical-token, semantic-c-debug-mode-init-pch)
(semantic-c-classname, semantic-format-tag-uml-prototype)
(semantic-c-dereference-namespace, semantic-analyze-type-constants):
* cedet/semantic/bovine/el.el (semantic-elisp-form-to-doc-string)
(semantic-emacs-lisp-obsoleted-doc, semantic-up-context)
(semantic-get-local-variables, semantic-end-of-command)
(semantic-beginning-of-command, semantic-ctxt-current-class-list)
(lisp-mode):
* cedet/semantic/bovine/make.el (makefile-mode):
* cedet/semantic/wisent/python.el (wisent-python-string-re)
(wisent-python-implicit-line-joining-p, wisent-python-forward-string)
(wisent-python-lex-beginning-of-line, wisent-python-lex-end-of-line)
(semantic-lex, semantic-get-local-variables, python-mode):
* cedet/semantic/wisent/python-wy.el (wisent-python-wy--keyword-table):
* cedet/srecode/extract.el (srecode-extract-state-set)
(srecode-extract-method): Fix typos in docstrings.
2010-01-12 05:51:26 +01:00
|
|
|
|
"Detect and create Python newline tokens.
|
2010-01-09 19:38:07 -05:00
|
|
|
|
Just skip the newline character if the following line is an implicit
|
|
|
|
|
continuation of current line."
|
|
|
|
|
"\\(\n\\|\\s>\\)"
|
|
|
|
|
(if (wisent-python-implicit-line-joining-p)
|
|
|
|
|
(setq semantic-lex-end-point (match-end 0))
|
|
|
|
|
(semantic-lex-push-token
|
|
|
|
|
(semantic-lex-token 'NEWLINE (point) (match-end 0)))))
|
|
|
|
|
|
|
|
|
|
(define-lex-regex-analyzer wisent-python-lex-string
|
|
|
|
|
"Detect and create python string tokens."
|
2012-10-02 02:10:29 +08:00
|
|
|
|
wisent-python-string-start-re
|
2010-01-09 19:38:07 -05:00
|
|
|
|
(semantic-lex-push-token
|
|
|
|
|
(semantic-lex-token
|
|
|
|
|
'STRING_LITERAL
|
|
|
|
|
(point)
|
|
|
|
|
(semantic-lex-unterminated-syntax-protection 'STRING_LITERAL
|
|
|
|
|
(wisent-python-forward-string)
|
|
|
|
|
(point)))))
|
|
|
|
|
|
|
|
|
|
(define-lex-regex-analyzer wisent-python-lex-ignore-backslash
|
|
|
|
|
"Detect and skip over backslash (explicit line joining) tokens.
|
|
|
|
|
A backslash must be the last token of a physical line, it is illegal
|
|
|
|
|
elsewhere on a line outside a string literal."
|
|
|
|
|
"\\s\\\\s-*$"
|
|
|
|
|
;; Skip over the detected backslash and go to the first
|
|
|
|
|
;; non-whitespace character in the next physical line.
|
|
|
|
|
(forward-line)
|
|
|
|
|
(skip-syntax-forward "-")
|
|
|
|
|
(setq semantic-lex-end-point (point)))
|
|
|
|
|
|
|
|
|
|
(define-lex wisent-python-lexer
|
|
|
|
|
"Lexical Analyzer for Python code."
|
|
|
|
|
;; Must analyze beginning of line first to handle indentation.
|
|
|
|
|
wisent-python-lex-beginning-of-line
|
|
|
|
|
wisent-python-lex-end-of-line
|
|
|
|
|
;; Must analyze string before symbol to handle string prefix.
|
|
|
|
|
wisent-python-lex-string
|
|
|
|
|
;; Analyzers auto-generated from grammar.
|
|
|
|
|
wisent-python-wy--<number>-regexp-analyzer
|
|
|
|
|
wisent-python-wy--<keyword>-keyword-analyzer
|
|
|
|
|
wisent-python-wy--<symbol>-regexp-analyzer
|
|
|
|
|
wisent-python-wy--<block>-block-analyzer
|
|
|
|
|
wisent-python-wy--<punctuation>-string-analyzer
|
|
|
|
|
;; Ignored things.
|
|
|
|
|
wisent-python-lex-ignore-backslash
|
|
|
|
|
semantic-lex-ignore-whitespace
|
|
|
|
|
semantic-lex-ignore-comments
|
|
|
|
|
;; Signal error on unhandled syntax.
|
|
|
|
|
semantic-lex-default-action)
|
2012-10-02 02:10:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Parsing
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
(defun wisent-python-reconstitute-function-tag (tag suite)
|
|
|
|
|
"Move a docstring from TAG's members into its :documentation attribute.
|
|
|
|
|
Set attributes for constructors, special, private and static methods."
|
|
|
|
|
;; Analyze first statement to see whether it is a documentation
|
|
|
|
|
;; string.
|
|
|
|
|
(let ((first-statement (car suite)))
|
|
|
|
|
(when (semantic-python-docstring-p first-statement)
|
|
|
|
|
(semantic-tag-put-attribute
|
|
|
|
|
tag :documentation
|
|
|
|
|
(semantic-python-extract-docstring first-statement))))
|
|
|
|
|
|
|
|
|
|
;; TODO HACK: we try to identify methods using the following
|
|
|
|
|
;; heuristic:
|
|
|
|
|
;; + at least one argument
|
|
|
|
|
;; + first argument is self
|
|
|
|
|
(when (and (> (length (semantic-tag-function-arguments tag)) 0)
|
|
|
|
|
(string= (semantic-tag-name
|
|
|
|
|
(first (semantic-tag-function-arguments tag)))
|
|
|
|
|
"self"))
|
|
|
|
|
(semantic-tag-put-attribute tag :parent "dummy"))
|
|
|
|
|
|
|
|
|
|
;; Identify constructors, special and private functions
|
|
|
|
|
(cond
|
|
|
|
|
;; TODO only valid when the function resides inside a class
|
|
|
|
|
((string= (semantic-tag-name tag) "__init__")
|
|
|
|
|
(semantic-tag-put-attribute tag :constructor-flag t)
|
|
|
|
|
(semantic-tag-put-attribute tag :suite suite))
|
|
|
|
|
|
|
|
|
|
((semantic-python-special-p tag)
|
|
|
|
|
(semantic-tag-put-attribute tag :special-flag t))
|
|
|
|
|
|
|
|
|
|
((semantic-python-private-p tag)
|
|
|
|
|
(semantic-tag-put-attribute tag :protection "private")))
|
|
|
|
|
|
|
|
|
|
;; If there is a staticmethod decorator, add a static typemodifier
|
|
|
|
|
;; for the function.
|
|
|
|
|
(when (semantic-find-tags-by-name
|
|
|
|
|
"staticmethod"
|
|
|
|
|
(semantic-tag-get-attribute tag :decorators))
|
|
|
|
|
(semantic-tag-put-attribute
|
|
|
|
|
tag :typemodifiers
|
|
|
|
|
(cons "static"
|
|
|
|
|
(semantic-tag-get-attribute tag :typemodifiers))))
|
|
|
|
|
|
|
|
|
|
;; TODO
|
|
|
|
|
;; + check for decorators classmethod
|
|
|
|
|
;; + check for operators
|
|
|
|
|
tag)
|
|
|
|
|
|
|
|
|
|
(defun wisent-python-reconstitute-class-tag (tag)
|
|
|
|
|
"Move a docstring from TAG's members into its :documentation attribute."
|
|
|
|
|
;; The first member of TAG may be a documentation string. If that is
|
|
|
|
|
;; the case, remove of it from the members list and stick its
|
|
|
|
|
;; content into the :documentation attribute.
|
|
|
|
|
(let ((first-member (car (semantic-tag-type-members tag))))
|
|
|
|
|
(when (semantic-python-docstring-p first-member)
|
|
|
|
|
(semantic-tag-put-attribute
|
|
|
|
|
tag :members
|
|
|
|
|
(cdr (semantic-tag-type-members tag)))
|
|
|
|
|
(semantic-tag-put-attribute
|
|
|
|
|
tag :documentation
|
|
|
|
|
(semantic-python-extract-docstring first-member))))
|
|
|
|
|
|
|
|
|
|
;; Try to find the constructor, determine the name of the instance
|
|
|
|
|
;; parameter, find assignments to instance variables and add
|
|
|
|
|
;; corresponding variable tags to the list of members.
|
|
|
|
|
(dolist (member (semantic-tag-type-members tag))
|
|
|
|
|
(when (semantic-tag-function-constructor-p member)
|
|
|
|
|
(let ((self (semantic-tag-name
|
|
|
|
|
(car (semantic-tag-function-arguments member)))))
|
|
|
|
|
(dolist (statement (semantic-tag-get-attribute member :suite))
|
|
|
|
|
(when (semantic-python-instance-variable-p statement self)
|
|
|
|
|
(let ((variable (semantic-tag-clone
|
|
|
|
|
statement
|
|
|
|
|
(substring (semantic-tag-name statement) 5)))
|
|
|
|
|
(members (semantic-tag-get-attribute tag :members)))
|
|
|
|
|
(when (semantic-python-private-p variable)
|
|
|
|
|
(semantic-tag-put-attribute variable :protection "private"))
|
|
|
|
|
(setcdr (last members) (list variable))))))))
|
|
|
|
|
|
|
|
|
|
;; TODO remove the :suite attribute
|
|
|
|
|
tag)
|
|
|
|
|
|
|
|
|
|
(defun semantic-python-expand-tag (tag)
|
|
|
|
|
"Expand compound declarations found in TAG into separate tags.
|
|
|
|
|
TAG contains compound declaration if the NAME part of the tag is
|
|
|
|
|
a list. In python, this can happen with `import' statements."
|
|
|
|
|
(let ((class (semantic-tag-class tag))
|
|
|
|
|
(elts (semantic-tag-name tag))
|
|
|
|
|
(expand nil))
|
|
|
|
|
(cond
|
|
|
|
|
((and (eq class 'include) (listp elts))
|
|
|
|
|
(dolist (E elts)
|
|
|
|
|
(setq expand (cons (semantic-tag-clone tag E) expand)))
|
|
|
|
|
(setq expand (nreverse expand)))
|
|
|
|
|
)))
|
|
|
|
|
|
|
|
|
|
|
2010-01-09 19:38:07 -05:00
|
|
|
|
|
|
|
|
|
;;; Overridden Semantic API.
|
|
|
|
|
;;
|
2012-10-02 02:10:29 +08:00
|
|
|
|
|
2010-01-09 19:38:07 -05:00
|
|
|
|
(define-mode-local-override semantic-lex python-mode
|
|
|
|
|
(start end &optional depth length)
|
Fix typos in CEDET docstrings.
* cedet/semantic/analyze.el (semantic-analyze-push-error)
(semantic-analyze-context, semantic-analyze-context-assignment)
(semantic-analyze-find-tag-sequence, semantic-analyze-find-tag):
* cedet/semantic/java.el (java-mode, semantic-tag-include-filename)
(semantic-java-doc-keywords-map):
* cedet/semantic/bovine/c.el (c-mode, semantic-c-member-of-autocast)
(semantic-lex-c-nested-namespace-ignore-second, semantic-parse-region)
(semantic-c-parse-lexical-token, semantic-c-debug-mode-init-pch)
(semantic-c-classname, semantic-format-tag-uml-prototype)
(semantic-c-dereference-namespace, semantic-analyze-type-constants):
* cedet/semantic/bovine/el.el (semantic-elisp-form-to-doc-string)
(semantic-emacs-lisp-obsoleted-doc, semantic-up-context)
(semantic-get-local-variables, semantic-end-of-command)
(semantic-beginning-of-command, semantic-ctxt-current-class-list)
(lisp-mode):
* cedet/semantic/bovine/make.el (makefile-mode):
* cedet/semantic/wisent/python.el (wisent-python-string-re)
(wisent-python-implicit-line-joining-p, wisent-python-forward-string)
(wisent-python-lex-beginning-of-line, wisent-python-lex-end-of-line)
(semantic-lex, semantic-get-local-variables, python-mode):
* cedet/semantic/wisent/python-wy.el (wisent-python-wy--keyword-table):
* cedet/srecode/extract.el (srecode-extract-state-set)
(srecode-extract-method): Fix typos in docstrings.
2010-01-12 05:51:26 +01:00
|
|
|
|
"Lexically analyze Python code in current buffer.
|
2010-01-09 19:38:07 -05:00
|
|
|
|
See the function `semantic-lex' for the meaning of the START, END,
|
|
|
|
|
DEPTH and LENGTH arguments.
|
|
|
|
|
This function calls `wisent-python-lexer' to actually perform the
|
Fix typos in CEDET docstrings.
* cedet/semantic/analyze.el (semantic-analyze-push-error)
(semantic-analyze-context, semantic-analyze-context-assignment)
(semantic-analyze-find-tag-sequence, semantic-analyze-find-tag):
* cedet/semantic/java.el (java-mode, semantic-tag-include-filename)
(semantic-java-doc-keywords-map):
* cedet/semantic/bovine/c.el (c-mode, semantic-c-member-of-autocast)
(semantic-lex-c-nested-namespace-ignore-second, semantic-parse-region)
(semantic-c-parse-lexical-token, semantic-c-debug-mode-init-pch)
(semantic-c-classname, semantic-format-tag-uml-prototype)
(semantic-c-dereference-namespace, semantic-analyze-type-constants):
* cedet/semantic/bovine/el.el (semantic-elisp-form-to-doc-string)
(semantic-emacs-lisp-obsoleted-doc, semantic-up-context)
(semantic-get-local-variables, semantic-end-of-command)
(semantic-beginning-of-command, semantic-ctxt-current-class-list)
(lisp-mode):
* cedet/semantic/bovine/make.el (makefile-mode):
* cedet/semantic/wisent/python.el (wisent-python-string-re)
(wisent-python-implicit-line-joining-p, wisent-python-forward-string)
(wisent-python-lex-beginning-of-line, wisent-python-lex-end-of-line)
(semantic-lex, semantic-get-local-variables, python-mode):
* cedet/semantic/wisent/python-wy.el (wisent-python-wy--keyword-table):
* cedet/srecode/extract.el (srecode-extract-state-set)
(srecode-extract-method): Fix typos in docstrings.
2010-01-12 05:51:26 +01:00
|
|
|
|
lexical analysis, then emits the necessary Python DEDENT tokens from
|
2010-01-09 19:38:07 -05:00
|
|
|
|
what remains in the `wisent-python-indent-stack'."
|
|
|
|
|
(let* ((wisent-python-indent-stack (list 0))
|
|
|
|
|
(stream (wisent-python-lexer start end depth length))
|
|
|
|
|
(semantic-lex-token-stream nil))
|
|
|
|
|
;; Emit DEDENT tokens if something remains in the INDENT stack.
|
|
|
|
|
(while (> (pop wisent-python-indent-stack) 0)
|
|
|
|
|
(semantic-lex-push-token (semantic-lex-token 'DEDENT end end)))
|
|
|
|
|
(nconc stream (nreverse semantic-lex-token-stream))))
|
|
|
|
|
|
|
|
|
|
(define-mode-local-override semantic-get-local-variables python-mode ()
|
|
|
|
|
"Get the local variables based on point's context.
|
Fix typos in CEDET docstrings.
* cedet/semantic/analyze.el (semantic-analyze-push-error)
(semantic-analyze-context, semantic-analyze-context-assignment)
(semantic-analyze-find-tag-sequence, semantic-analyze-find-tag):
* cedet/semantic/java.el (java-mode, semantic-tag-include-filename)
(semantic-java-doc-keywords-map):
* cedet/semantic/bovine/c.el (c-mode, semantic-c-member-of-autocast)
(semantic-lex-c-nested-namespace-ignore-second, semantic-parse-region)
(semantic-c-parse-lexical-token, semantic-c-debug-mode-init-pch)
(semantic-c-classname, semantic-format-tag-uml-prototype)
(semantic-c-dereference-namespace, semantic-analyze-type-constants):
* cedet/semantic/bovine/el.el (semantic-elisp-form-to-doc-string)
(semantic-emacs-lisp-obsoleted-doc, semantic-up-context)
(semantic-get-local-variables, semantic-end-of-command)
(semantic-beginning-of-command, semantic-ctxt-current-class-list)
(lisp-mode):
* cedet/semantic/bovine/make.el (makefile-mode):
* cedet/semantic/wisent/python.el (wisent-python-string-re)
(wisent-python-implicit-line-joining-p, wisent-python-forward-string)
(wisent-python-lex-beginning-of-line, wisent-python-lex-end-of-line)
(semantic-lex, semantic-get-local-variables, python-mode):
* cedet/semantic/wisent/python-wy.el (wisent-python-wy--keyword-table):
* cedet/srecode/extract.el (srecode-extract-state-set)
(srecode-extract-method): Fix typos in docstrings.
2010-01-12 05:51:26 +01:00
|
|
|
|
To be implemented for Python! For now just return nil."
|
2010-01-09 19:38:07 -05:00
|
|
|
|
nil)
|
|
|
|
|
|
2012-10-02 02:10:29 +08:00
|
|
|
|
;; Adapted from the semantic Java support by Andrey Torba
|
|
|
|
|
(define-mode-local-override semantic-tag-include-filename python-mode (tag)
|
|
|
|
|
"Return a suitable path for (some) Python imports."
|
|
|
|
|
(let ((name (semantic-tag-name tag)))
|
|
|
|
|
(concat (mapconcat 'identity (split-string name "\\.") "/") ".py")))
|
2010-01-09 19:38:07 -05:00
|
|
|
|
|
2012-10-07 20:23:50 +02:00
|
|
|
|
;; Override ctxt-current-function/assignment defaults, since they do
|
|
|
|
|
;; not work properly with Python code, even leading to endless loops
|
|
|
|
|
;; (see bug #xxxxx).
|
|
|
|
|
(define-mode-local-override semantic-ctxt-current-function python-mode (&optional point)
|
|
|
|
|
"Return the current function call the cursor is in at POINT.
|
|
|
|
|
The function returned is the one accepting the arguments that
|
|
|
|
|
the cursor is currently in. It will not return function symbol if the
|
|
|
|
|
cursor is on the text representing that function."
|
|
|
|
|
nil)
|
|
|
|
|
|
|
|
|
|
(define-mode-local-override semantic-ctxt-current-assignment python-mode (&optional point)
|
|
|
|
|
"Return the current assignment near the cursor at POINT.
|
|
|
|
|
Return a list as per `semantic-ctxt-current-symbol'.
|
|
|
|
|
Return nil if there is nothing relevant."
|
|
|
|
|
nil)
|
|
|
|
|
|
Merge from CEDET upstream (8564).
* lisp/emacs-lisp:
* emacs-lisp/eieio.el (eieio--defalias, eieio-hook)
(eieio-error-unsupported-class-tags, eieio-skip-typecheck)
(eieio-optimize-primary-methods-flag, eieio-initializing-object)
(eieio-unbound, eieio-default-superclass)
(eieio--define-field-accessors, method-static, method-before)
(method-primary, method-after, method-num-lists)
(method-generic-before, method-generic-primary)
(method-generic-after, method-num-slots)
(eieio-specialized-key-to-generic-key)
(eieio--check-type, class-v, class-p)
(eieio-class-name, define-obsolete-function-alias)
(eieio-class-parents-fast, eieio-class-children-fast)
(same-class-fast-p, class-constructor, generic-p)
(generic-primary-only-p, generic-primary-only-one-p)
(class-option-assoc, class-option, eieio-object-p)
(class-abstract-p, class-method-invocation-order)
(eieio-defclass-autoload-map, eieio-defclass-autoload)
(eieio-class-un-autoload, eieio-defclass)
(eieio-eval-default-p, eieio-perform-slot-validation-for-default)
(eieio-add-new-slot, eieio-copy-parents-into-subclass)
(eieio--defgeneric-init-form, eieio-defgeneric-form)
(eieio-defgeneric-reset-generic-form)
(eieio-defgeneric-form-primary-only)
(eieio-defgeneric-reset-generic-form-primary-only)
(eieio-defgeneric-form-primary-only-one)
(eieio-defgeneric-reset-generic-form-primary-only-one)
(eieio-unbind-method-implementations)
(eieio--defmethod, eieio--typep)
(eieio-perform-slot-validation, eieio-validate-slot-value)
(eieio-validate-class-slot-value, eieio-barf-if-slot-unbound)
(eieio-oref, eieio-oref-default, eieio-default-eval-maybe)
(eieio-oset, eieio-oset-default, eieio-slot-originating-class-p)
(eieio-slot-name-index, eieio-class-slot-name-index)
(eieio-set-defaults, eieio-initarg-to-attribute)
(eieio-attribute-to-initarg, eieio-c3-candidate)
(eieio-c3-merge-lists, eieio-class-precedence-c3)
(eieio-class-precedence-dfs, eieio-class-precedence-bfs)
(eieio-class-precedence-list, eieio-generic-call-methodname)
(eieio-generic-call-arglst, eieio-generic-call-key)
(eieio-generic-call-next-method-list)
(eieio-pre-method-execution-functions, eieio-generic-call)
(eieio-generic-call-primary-only, eieiomt-method-list)
(eieiomt-optimizing-obarray, eieiomt-install)
(eieiomt-add, eieiomt-next, eieiomt-sym-optimize)
(eieio-generic-form, eieio-defmethod, make-obsolete)
(eieio-defgeneric, make-obsolete): Moved to eieio-core.el
(defclass): Remove `eval-and-compile' from macro.
(call-next-method, shared-initialize): Instead of using
`scoped-class' variable, use new eieio--scoped-class, and
eieio--with-scoped-class.
(initialize-instance): Rename local variable 'scoped-class' to
'this-class' to remove ambiguitity from old global.
* emacs-lisp/eieio-core.el: New file. Derived from key parts of
eieio.el.
(eieio--scoped-class-stack): New variable
(eieio--scoped-class): New fcn
(eieio--with-scoped-class): New scoping macro.
(eieio-defclass): Use pushnew instead of add-to-list.
(eieio-defgeneric-form-primary-only-one, eieio-oset-default)
(eieio-slot-name-index, eieio-set-defaults, eieio-generic-call)
(eieio-generic-call-primary-only, eieiomt-add): Instead of using
`scoped-class' variable, use new eieio--scoped-class, and
eieio--with-scoped-class.
* emacs-lisp/eieio-base.el (cl-lib): Require during compile.
* admin/grammars:
* grammars/srecode-template.wy (variable): Accept a single number
as a variable value. Allows the 'priority' to be set to a number.
(wisent-srecode-template-lexer): Move number up so it can be
created.
* etc/srecode:
* srecode/c.srt (header_guard): Add :c parameter so it works
standalone
* lisp/cedet:
* semantic/edit.el (semantic-change-function): Use
`save-match-data' around running hooks.
* semantic/decorate/mode.el
(semantic-decorate-style-predicate-default)
(semantic-decorate-style-highlighter-default): New.
(semantic-decoration-mode): Do not require
`semantic/decorate/include' anymore.
(semantic-toggle-decoration-style): Error if an unknown decoration
style is toggled.
(define-semantic-decoration-style): Add new :load option. When
:load is specified, add autoload tokens for the definition
functions so that code is loaded when the mode is used.
(semantic-decoration-on-includes): New autoload definition for
highlighting includes.
* semantic/bovine/c.el (semantic-lex-c-ifdef): Allow some misc
characters to appear after the tested variable.
* semantic/ede-grammar.el (project-compile-target): Calculate full
src name via ede-expand-filename instead of the crutch of the
current buffer. Enables this target to compile in batch mode.
* semantic/idle.el
(semantic-idle-symbol-maybe-highlight): Wrap highlighting of
remote symbol with `save-excursion'.
(semantic-idle-scheduler-work-parse-neighboring-files): Instead of
using directory-files on each found mode pattern, collect all the
patterns for the current mode, and then for each file, see if it
matches any of them. If it does, parse the file. (Patch
inspiration from Tomasz Gajewski.)
* semantic/ctxt.el (semantic-ctxt-end-of-symbol): New.
(semantic-ctxt-current-symbol-default): New.
* semantic/bovine/el.el (semantic-default-elisp-setup): Add
autoload cookie. Explain existence.
(footer): Add local variable for loaddefs.
* semantic/db.el (semanticdb-file-table-object): Add new filter,
only checking for regular files too.
* semantic/wisent/python.el
(semantic-format-tag-abbreviate): New override. Cuts back on size
of code tags.
* srecode/compile.el (srecode-compile-templates): Fix warning
punctuation. Remove status messages to clean up testing output
* ede/base.el (ede-project-placeholder-cache-file): Update doc to
mention 'nil' value.
(ede-save-cache): Disable cache save if file is nil.
* ede.el (ede-initialize-state-current-buffer): Flush deleted
projects.
(global-ede-mode): Always append our find-file-hook to the end.
(ede-flush-deleted-projects): New command.
* ede/cpp-root.el (ede-preprocessor-map): Protect against init
problems.
* ede/proj.el (ede-proj-target): Added a new "custom" option for
custom symbols representing a compiler or linker instead of
restricting things to only the predefined compilers and linkers.
* semantic.el (semantic-mode-map): To avoid showing showing
Development menu twice, only disable menu item if menu-bar is
actually enabled, otherwise the popup 'global menu' might display
a disabled Development menu.
* semantic/complete.el
(semantic-displayor-show-request): Fix which slot in obj is set to
the max tags.
2013-06-02 15:33:09 +02:00
|
|
|
|
;;; Tag Formatting
|
|
|
|
|
;;
|
|
|
|
|
(define-mode-local-override semantic-format-tag-abbreviate python-mode (tag &optional parent color)
|
|
|
|
|
"Format an abbreviated tag for python.
|
Prefer directed to neutral quotes
Prefer directed to neutral quotes in docstings and diagnostics.
In docstrings, escape apostrophes that would otherwise be translated
to curved quotes using the newer, simpler rules.
* admin/unidata/unidata-gen.el (unidata-gen-table):
* lisp/align.el (align-region):
* lisp/allout.el (allout-mode, allout-solicit-alternate-bullet):
* lisp/bookmark.el (bookmark-default-annotation-text):
* lisp/calc/calc-aent.el (math-read-if, math-read-factor):
* lisp/calc/calc-lang.el (math-read-giac-subscr)
(math-read-math-subscr):
* lisp/calc/calc-misc.el (report-calc-bug):
* lisp/calc/calc-prog.el (calc-fix-token-name)
(calc-read-parse-table-part):
* lisp/cedet/ede/pmake.el (ede-proj-makefile-insert-dist-rules):
* lisp/cedet/semantic/complete.el (semantic-displayor-show-request):
* lisp/dabbrev.el (dabbrev-expand):
* lisp/emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine):
* lisp/emacs-lisp/elint.el (elint-get-top-forms):
* lisp/emacs-lisp/lisp-mnt.el (lm-verify):
* lisp/emulation/viper-cmd.el (viper-toggle-search-style):
* lisp/erc/erc-button.el (erc-nick-popup):
* lisp/erc/erc.el (erc-cmd-LOAD, erc-handle-login):
* lisp/eshell/em-dirs.el (eshell/cd):
* lisp/eshell/em-glob.el (eshell-glob-regexp):
* lisp/eshell/em-pred.el (eshell-parse-modifiers):
* lisp/eshell/esh-arg.el (eshell-parse-arguments):
* lisp/eshell/esh-opt.el (eshell-show-usage):
* lisp/files-x.el (modify-file-local-variable):
* lisp/filesets.el (filesets-add-buffer, filesets-remove-buffer)
(filesets-update-pre010505):
* lisp/find-cmd.el (find-generic, find-to-string):
* lisp/gnus/auth-source.el (auth-source-netrc-parse-entries):
* lisp/gnus/gnus-agent.el (gnus-agent-check-overview-buffer)
(gnus-agent-fetch-headers):
* lisp/gnus/gnus-int.el (gnus-start-news-server):
* lisp/gnus/gnus-registry.el:
(gnus-registry--split-fancy-with-parent-internal):
* lisp/gnus/gnus-score.el (gnus-summary-increase-score):
* lisp/gnus/gnus-start.el (gnus-convert-old-newsrc):
* lisp/gnus/gnus-topic.el (gnus-topic-rename):
* lisp/gnus/legacy-gnus-agent.el (gnus-agent-unlist-expire-days):
* lisp/gnus/nnmairix.el (nnmairix-widget-create-query):
* lisp/gnus/spam.el (spam-check-blackholes):
* lisp/mail/feedmail.el (feedmail-run-the-queue):
* lisp/mpc.el (mpc-playlist-rename):
* lisp/net/ange-ftp.el (ange-ftp-shell-command):
* lisp/net/mairix.el (mairix-widget-create-query):
* lisp/net/tramp-cache.el:
* lisp/obsolete/otodo-mode.el (todo-more-important-p):
* lisp/obsolete/pgg-gpg.el (pgg-gpg-process-region):
* lisp/obsolete/pgg-pgp.el (pgg-pgp-process-region):
* lisp/obsolete/pgg-pgp5.el (pgg-pgp5-process-region):
* lisp/org/ob-core.el (org-babel-goto-named-src-block)
(org-babel-goto-named-result):
* lisp/org/ob-fortran.el (org-babel-fortran-ensure-main-wrap):
* lisp/org/ob-ref.el (org-babel-ref-resolve):
* lisp/org/org-agenda.el (org-agenda-prepare):
* lisp/org/org-bibtex.el (org-bibtex-fields):
* lisp/org/org-clock.el (org-clock-notify-once-if-expired)
(org-clock-resolve):
* lisp/org/org-feed.el (org-feed-parse-atom-entry):
* lisp/org/org-habit.el (org-habit-parse-todo):
* lisp/org/org-mouse.el (org-mouse-popup-global-menu)
(org-mouse-context-menu):
* lisp/org/org-table.el (org-table-edit-formulas):
* lisp/org/ox.el (org-export-async-start):
* lisp/play/dunnet.el (dun-score, dun-help, dun-endgame-question)
(dun-rooms, dun-endgame-questions):
* lisp/progmodes/ada-mode.el (ada-goto-matching-start):
* lisp/progmodes/ada-xref.el (ada-find-executable):
* lisp/progmodes/antlr-mode.el (antlr-options-alists):
* lisp/progmodes/flymake.el (flymake-parse-err-lines)
(flymake-start-syntax-check-process):
* lisp/progmodes/python.el (python-define-auxiliary-skeleton):
* lisp/progmodes/sql.el (sql-comint):
* lisp/progmodes/verilog-mode.el (verilog-load-file-at-point):
* lisp/server.el (server-get-auth-key):
* lisp/subr.el (version-to-list):
* lisp/textmodes/reftex-ref.el (reftex-label):
* lisp/textmodes/reftex-toc.el (reftex-toc-rename-label):
* lisp/vc/ediff-diff.el (ediff-same-contents):
* lisp/vc/vc-cvs.el (vc-cvs-mode-line-string):
* test/automated/tramp-tests.el (tramp-test33-asynchronous-requests):
Use directed rather than neutral quotes in diagnostics.
2015-08-24 23:39:33 -07:00
|
|
|
|
Shortens `code' tags, but passes through for others."
|
Merge from CEDET upstream (8564).
* lisp/emacs-lisp:
* emacs-lisp/eieio.el (eieio--defalias, eieio-hook)
(eieio-error-unsupported-class-tags, eieio-skip-typecheck)
(eieio-optimize-primary-methods-flag, eieio-initializing-object)
(eieio-unbound, eieio-default-superclass)
(eieio--define-field-accessors, method-static, method-before)
(method-primary, method-after, method-num-lists)
(method-generic-before, method-generic-primary)
(method-generic-after, method-num-slots)
(eieio-specialized-key-to-generic-key)
(eieio--check-type, class-v, class-p)
(eieio-class-name, define-obsolete-function-alias)
(eieio-class-parents-fast, eieio-class-children-fast)
(same-class-fast-p, class-constructor, generic-p)
(generic-primary-only-p, generic-primary-only-one-p)
(class-option-assoc, class-option, eieio-object-p)
(class-abstract-p, class-method-invocation-order)
(eieio-defclass-autoload-map, eieio-defclass-autoload)
(eieio-class-un-autoload, eieio-defclass)
(eieio-eval-default-p, eieio-perform-slot-validation-for-default)
(eieio-add-new-slot, eieio-copy-parents-into-subclass)
(eieio--defgeneric-init-form, eieio-defgeneric-form)
(eieio-defgeneric-reset-generic-form)
(eieio-defgeneric-form-primary-only)
(eieio-defgeneric-reset-generic-form-primary-only)
(eieio-defgeneric-form-primary-only-one)
(eieio-defgeneric-reset-generic-form-primary-only-one)
(eieio-unbind-method-implementations)
(eieio--defmethod, eieio--typep)
(eieio-perform-slot-validation, eieio-validate-slot-value)
(eieio-validate-class-slot-value, eieio-barf-if-slot-unbound)
(eieio-oref, eieio-oref-default, eieio-default-eval-maybe)
(eieio-oset, eieio-oset-default, eieio-slot-originating-class-p)
(eieio-slot-name-index, eieio-class-slot-name-index)
(eieio-set-defaults, eieio-initarg-to-attribute)
(eieio-attribute-to-initarg, eieio-c3-candidate)
(eieio-c3-merge-lists, eieio-class-precedence-c3)
(eieio-class-precedence-dfs, eieio-class-precedence-bfs)
(eieio-class-precedence-list, eieio-generic-call-methodname)
(eieio-generic-call-arglst, eieio-generic-call-key)
(eieio-generic-call-next-method-list)
(eieio-pre-method-execution-functions, eieio-generic-call)
(eieio-generic-call-primary-only, eieiomt-method-list)
(eieiomt-optimizing-obarray, eieiomt-install)
(eieiomt-add, eieiomt-next, eieiomt-sym-optimize)
(eieio-generic-form, eieio-defmethod, make-obsolete)
(eieio-defgeneric, make-obsolete): Moved to eieio-core.el
(defclass): Remove `eval-and-compile' from macro.
(call-next-method, shared-initialize): Instead of using
`scoped-class' variable, use new eieio--scoped-class, and
eieio--with-scoped-class.
(initialize-instance): Rename local variable 'scoped-class' to
'this-class' to remove ambiguitity from old global.
* emacs-lisp/eieio-core.el: New file. Derived from key parts of
eieio.el.
(eieio--scoped-class-stack): New variable
(eieio--scoped-class): New fcn
(eieio--with-scoped-class): New scoping macro.
(eieio-defclass): Use pushnew instead of add-to-list.
(eieio-defgeneric-form-primary-only-one, eieio-oset-default)
(eieio-slot-name-index, eieio-set-defaults, eieio-generic-call)
(eieio-generic-call-primary-only, eieiomt-add): Instead of using
`scoped-class' variable, use new eieio--scoped-class, and
eieio--with-scoped-class.
* emacs-lisp/eieio-base.el (cl-lib): Require during compile.
* admin/grammars:
* grammars/srecode-template.wy (variable): Accept a single number
as a variable value. Allows the 'priority' to be set to a number.
(wisent-srecode-template-lexer): Move number up so it can be
created.
* etc/srecode:
* srecode/c.srt (header_guard): Add :c parameter so it works
standalone
* lisp/cedet:
* semantic/edit.el (semantic-change-function): Use
`save-match-data' around running hooks.
* semantic/decorate/mode.el
(semantic-decorate-style-predicate-default)
(semantic-decorate-style-highlighter-default): New.
(semantic-decoration-mode): Do not require
`semantic/decorate/include' anymore.
(semantic-toggle-decoration-style): Error if an unknown decoration
style is toggled.
(define-semantic-decoration-style): Add new :load option. When
:load is specified, add autoload tokens for the definition
functions so that code is loaded when the mode is used.
(semantic-decoration-on-includes): New autoload definition for
highlighting includes.
* semantic/bovine/c.el (semantic-lex-c-ifdef): Allow some misc
characters to appear after the tested variable.
* semantic/ede-grammar.el (project-compile-target): Calculate full
src name via ede-expand-filename instead of the crutch of the
current buffer. Enables this target to compile in batch mode.
* semantic/idle.el
(semantic-idle-symbol-maybe-highlight): Wrap highlighting of
remote symbol with `save-excursion'.
(semantic-idle-scheduler-work-parse-neighboring-files): Instead of
using directory-files on each found mode pattern, collect all the
patterns for the current mode, and then for each file, see if it
matches any of them. If it does, parse the file. (Patch
inspiration from Tomasz Gajewski.)
* semantic/ctxt.el (semantic-ctxt-end-of-symbol): New.
(semantic-ctxt-current-symbol-default): New.
* semantic/bovine/el.el (semantic-default-elisp-setup): Add
autoload cookie. Explain existence.
(footer): Add local variable for loaddefs.
* semantic/db.el (semanticdb-file-table-object): Add new filter,
only checking for regular files too.
* semantic/wisent/python.el
(semantic-format-tag-abbreviate): New override. Cuts back on size
of code tags.
* srecode/compile.el (srecode-compile-templates): Fix warning
punctuation. Remove status messages to clean up testing output
* ede/base.el (ede-project-placeholder-cache-file): Update doc to
mention 'nil' value.
(ede-save-cache): Disable cache save if file is nil.
* ede.el (ede-initialize-state-current-buffer): Flush deleted
projects.
(global-ede-mode): Always append our find-file-hook to the end.
(ede-flush-deleted-projects): New command.
* ede/cpp-root.el (ede-preprocessor-map): Protect against init
problems.
* ede/proj.el (ede-proj-target): Added a new "custom" option for
custom symbols representing a compiler or linker instead of
restricting things to only the predefined compilers and linkers.
* semantic.el (semantic-mode-map): To avoid showing showing
Development menu twice, only disable menu item if menu-bar is
actually enabled, otherwise the popup 'global menu' might display
a disabled Development menu.
* semantic/complete.el
(semantic-displayor-show-request): Fix which slot in obj is set to
the max tags.
2013-06-02 15:33:09 +02:00
|
|
|
|
(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))))
|
|
|
|
|
|
2010-01-09 19:38:07 -05:00
|
|
|
|
;;; Enable Semantic in `python-mode'.
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun wisent-python-default-setup ()
|
|
|
|
|
"Setup buffer for parse."
|
|
|
|
|
(wisent-python-wy--install-parser)
|
|
|
|
|
(set (make-local-variable 'parse-sexp-ignore-comments) t)
|
2012-10-02 02:10:29 +08:00
|
|
|
|
;; Give python modes the possibility to overwrite this:
|
|
|
|
|
(if (not comment-start-skip)
|
|
|
|
|
(set (make-local-variable 'comment-start-skip) "#+\\s-*"))
|
2010-01-09 19:38:07 -05:00
|
|
|
|
(setq
|
2012-10-02 02:10:29 +08:00
|
|
|
|
;; Character used to separation a parent/child relationship
|
2010-01-09 19:38:07 -05:00
|
|
|
|
semantic-type-relation-separator-character '(".")
|
|
|
|
|
semantic-command-separation-character ";"
|
2012-10-02 02:10:29 +08:00
|
|
|
|
;; Parsing
|
|
|
|
|
semantic-tag-expand-function 'semantic-python-expand-tag
|
2010-01-09 19:38:07 -05:00
|
|
|
|
|
|
|
|
|
;; Semantic to take over from the one provided by python.
|
|
|
|
|
;; The python one, if it uses the senator advice, will hang
|
|
|
|
|
;; Emacs unrecoverably.
|
|
|
|
|
imenu-create-index-function 'semantic-create-imenu-index
|
|
|
|
|
|
|
|
|
|
;; I need a python guru to update this list:
|
|
|
|
|
semantic-symbol->name-assoc-list-for-type-parts '((variable . "Variables")
|
|
|
|
|
(function . "Methods"))
|
|
|
|
|
semantic-symbol->name-assoc-list '((type . "Classes")
|
|
|
|
|
(variable . "Variables")
|
|
|
|
|
(function . "Functions")
|
|
|
|
|
(include . "Imports")
|
|
|
|
|
(package . "Package")
|
|
|
|
|
(code . "Code")))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
;; Make sure the newer python modes pull in the same python
|
|
|
|
|
;; mode overrides.
|
|
|
|
|
(define-child-mode python-2-mode python-mode "Python 2 mode")
|
|
|
|
|
(define-child-mode python-3-mode python-mode "Python 3 mode")
|
|
|
|
|
|
2012-10-02 02:10:29 +08:00
|
|
|
|
|
|
|
|
|
;;; Utility functions
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
(defun semantic-python-special-p (tag)
|
|
|
|
|
"Return non-nil if the name of TAG is a special identifier of
|
|
|
|
|
the form __NAME__. "
|
|
|
|
|
(string-match
|
|
|
|
|
(rx (seq string-start "__" (1+ (syntax symbol)) "__" string-end))
|
|
|
|
|
(semantic-tag-name tag)))
|
|
|
|
|
|
|
|
|
|
(defun semantic-python-private-p (tag)
|
|
|
|
|
"Return non-nil if the name of TAG follows the convention _NAME
|
|
|
|
|
for private names."
|
|
|
|
|
(string-match
|
|
|
|
|
(rx (seq string-start "_" (0+ (syntax symbol)) string-end))
|
|
|
|
|
(semantic-tag-name tag)))
|
|
|
|
|
|
|
|
|
|
(defun semantic-python-instance-variable-p (tag &optional self)
|
|
|
|
|
"Return non-nil if TAG is an instance variable of the instance
|
|
|
|
|
SELF or the instance name \"self\" if SELF is nil."
|
|
|
|
|
(when (semantic-tag-of-class-p tag 'variable)
|
|
|
|
|
(let ((name (semantic-tag-name tag)))
|
|
|
|
|
(when (string-match
|
|
|
|
|
(rx-to-string
|
|
|
|
|
`(seq string-start ,(or self "self") "."))
|
|
|
|
|
name)
|
|
|
|
|
(not (string-match "\\." (substring name 5)))))))
|
|
|
|
|
|
|
|
|
|
(defun semantic-python-docstring-p (tag)
|
|
|
|
|
"Return non-nil, when TAG is a Python documentation string."
|
|
|
|
|
;; TAG is considered to be a documentation string if the first
|
|
|
|
|
;; member is of class 'code and its name looks like a documentation
|
|
|
|
|
;; string.
|
|
|
|
|
(let ((class (semantic-tag-class tag))
|
|
|
|
|
(name (semantic-tag-name tag)))
|
|
|
|
|
(and (eq class 'code)
|
|
|
|
|
(string-match
|
|
|
|
|
(rx (seq string-start "\"\"\"" (0+ anything) "\"\"\"" string-end))
|
|
|
|
|
name))))
|
|
|
|
|
|
|
|
|
|
(defun semantic-python-extract-docstring (tag)
|
|
|
|
|
"Return the Python documentation string contained in TAG."
|
|
|
|
|
;; Strip leading and trailing """
|
|
|
|
|
(let ((name (semantic-tag-name tag)))
|
|
|
|
|
(substring name 3 -3)))
|
|
|
|
|
|
2010-01-09 19:38:07 -05:00
|
|
|
|
|
|
|
|
|
;;; Test
|
|
|
|
|
;;
|
2012-10-02 02:10:29 +08:00
|
|
|
|
|
2010-01-09 19:38:07 -05:00
|
|
|
|
(defun wisent-python-lex-buffer ()
|
|
|
|
|
"Run `wisent-python-lexer' on current buffer."
|
|
|
|
|
(interactive)
|
|
|
|
|
(semantic-lex-init)
|
|
|
|
|
(let ((token-stream (semantic-lex (point-min) (point-max) 0)))
|
|
|
|
|
(with-current-buffer (get-buffer-create "*wisent-python-lexer*")
|
|
|
|
|
(erase-buffer)
|
|
|
|
|
(pp token-stream (current-buffer))
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(pop-to-buffer (current-buffer)))))
|
|
|
|
|
|
|
|
|
|
(provide 'semantic/wisent/python)
|
|
|
|
|
|
|
|
|
|
;; Local variables:
|
|
|
|
|
;; generated-autoload-file: "../loaddefs.el"
|
|
|
|
|
;; generated-autoload-load-name: "semantic/wisent/python"
|
|
|
|
|
;; End:
|
|
|
|
|
|
|
|
|
|
;;; semantic/wisent/python.el ends here
|