ctxt.el 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. ;;; semantic/ctxt.el --- Context calculations for Semantic tools.
  2. ;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <zappo@gnu.org>
  4. ;; Keywords: syntax
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;;
  18. ;; Semantic, as a tool, provides a nice list of searchable tags.
  19. ;; That information can provide some very accurate answers if the current
  20. ;; context of a position is known.
  21. ;;
  22. ;; This library provides the hooks needed for a language to specify how
  23. ;; the current context is calculated.
  24. ;;
  25. (require 'semantic)
  26. ;;; Code:
  27. (defvar semantic-command-separation-character
  28. ";"
  29. "String which indicates the end of a command.
  30. Used for identifying the end of a single command.")
  31. (make-variable-buffer-local 'semantic-command-separation-character)
  32. (defvar semantic-function-argument-separation-character
  33. ","
  34. "String which indicates the end of an argument.
  35. Used for identifying arguments to functions.")
  36. (make-variable-buffer-local 'semantic-function-argument-separation-character)
  37. ;;; Local Contexts
  38. ;;
  39. ;; These context are nested blocks of code, such as code in an
  40. ;; if clause
  41. (declare-function semantic-current-tag-of-class "semantic/find")
  42. (define-overloadable-function semantic-up-context (&optional point bounds-type)
  43. "Move point up one context from POINT.
  44. Return non-nil if there are no more context levels.
  45. Overloaded functions using `up-context' take no parameters.
  46. BOUNDS-TYPE is a symbol representing a tag class to restrict
  47. movement to. If this is nil, 'function is used.
  48. This will find the smallest tag of that class (function, variable,
  49. type, etc) and make sure non-nil is returned if you cannot
  50. go up past the bounds of that tag."
  51. (require 'semantic/find)
  52. (if point (goto-char point))
  53. (let ((nar (semantic-current-tag-of-class (or bounds-type 'function))))
  54. (if nar
  55. (semantic-with-buffer-narrowed-to-tag nar (:override-with-args ()))
  56. (when bounds-type
  57. (error "No context of type %s to advance in" bounds-type))
  58. (:override-with-args ()))))
  59. (defun semantic-up-context-default ()
  60. "Move the point up and out one context level.
  61. Works with languages that use parenthetical grouping."
  62. ;; By default, assume that the language uses some form of parenthetical
  63. ;; do dads for their context.
  64. (condition-case nil
  65. (progn
  66. (up-list -1)
  67. nil)
  68. (error t)))
  69. (define-overloadable-function semantic-beginning-of-context (&optional point)
  70. "Move POINT to the beginning of the current context.
  71. Return non-nil if there is no upper context.
  72. The default behavior uses `semantic-up-context'.")
  73. (defun semantic-beginning-of-context-default (&optional point)
  74. "Move POINT to the beginning of the current context via parenthesis.
  75. Return non-nil if there is no upper context."
  76. (if point (goto-char point))
  77. (if (semantic-up-context)
  78. t
  79. (forward-char 1)
  80. nil))
  81. (define-overloadable-function semantic-end-of-context (&optional point)
  82. "Move POINT to the end of the current context.
  83. Return non-nil if there is no upper context.
  84. Be default, this uses `semantic-up-context', and assumes parenthetical
  85. block delimiters.")
  86. (defun semantic-end-of-context-default (&optional point)
  87. "Move POINT to the end of the current context via parenthesis.
  88. Return non-nil if there is no upper context."
  89. (if point (goto-char point))
  90. (let ((start (point)))
  91. (if (semantic-up-context)
  92. t
  93. ;; Go over the list, and back over the end parenthesis.
  94. (condition-case nil
  95. (progn
  96. (forward-sexp 1)
  97. (forward-char -1))
  98. (error
  99. ;; If an error occurs, get the current tag from the cache,
  100. ;; and just go to the end of that. Make sure we end up at least
  101. ;; where start was so parse-region type calls work.
  102. (if (semantic-current-tag)
  103. (progn
  104. (goto-char (semantic-tag-end (semantic-current-tag)))
  105. (when (< (point) start)
  106. (goto-char start)))
  107. (goto-char start))
  108. t)))
  109. nil))
  110. (defun semantic-narrow-to-context ()
  111. "Narrow the buffer to the extent of the current context."
  112. (let (b e)
  113. (save-excursion
  114. (if (semantic-beginning-of-context)
  115. nil
  116. (setq b (point))))
  117. (save-excursion
  118. (if (semantic-end-of-context)
  119. nil
  120. (setq e (point))))
  121. (if (and b e) (narrow-to-region b e))))
  122. (defmacro semantic-with-buffer-narrowed-to-context (&rest body)
  123. "Execute BODY with the buffer narrowed to the current context."
  124. `(save-restriction
  125. (semantic-narrow-to-context)
  126. ,@body))
  127. (put 'semantic-with-buffer-narrowed-to-context 'lisp-indent-function 0)
  128. (add-hook 'edebug-setup-hook
  129. (lambda ()
  130. (def-edebug-spec semantic-with-buffer-narrowed-to-context
  131. (def-body))))
  132. ;;; Local Variables
  133. ;;
  134. ;;
  135. (define-overloadable-function semantic-get-local-variables (&optional point)
  136. "Get the local variables based on POINT's context.
  137. Local variables are returned in Semantic tag format.
  138. This can be overridden with `get-local-variables'."
  139. ;; Disable parsing messages
  140. (let ((semantic--progress-reporter nil))
  141. (save-excursion
  142. (if point (goto-char point))
  143. (let* ((case-fold-search semantic-case-fold))
  144. (:override-with-args ())))))
  145. (defun semantic-get-local-variables-default ()
  146. "Get local values from a specific context.
  147. Uses the bovinator with the special top-symbol `bovine-inner-scope'
  148. to collect tags, such as local variables or prototypes."
  149. ;; This assumes a bovine parser. Make sure we don't do
  150. ;; anything in that case.
  151. (when (and semantic--parse-table (not (eq semantic--parse-table t))
  152. (not (semantic-parse-tree-unparseable-p)))
  153. (let ((vars (semantic-get-cache-data 'get-local-variables)))
  154. (if vars
  155. (progn
  156. ;;(message "Found cached vars.")
  157. vars)
  158. (let ((vars2 nil)
  159. ;; We want nothing to do with funny syntaxing while doing this.
  160. (semantic-unmatched-syntax-hook nil)
  161. (start (point))
  162. (firstusefulstart nil)
  163. )
  164. (while (not (semantic-up-context (point) 'function))
  165. (when (not vars)
  166. (setq firstusefulstart (point)))
  167. (save-excursion
  168. (forward-char 1)
  169. (setq vars
  170. ;; Note to self: semantic-parse-region returns cooked
  171. ;; but unlinked tags. File information is lost here
  172. ;; and is added next.
  173. (append (semantic-parse-region
  174. (point)
  175. (save-excursion (semantic-end-of-context) (point))
  176. 'bovine-inner-scope
  177. nil
  178. t)
  179. vars))))
  180. ;; Modify the tags in place.
  181. (setq vars2 vars)
  182. (while vars2
  183. (semantic--tag-put-property (car vars2) :filename (buffer-file-name))
  184. (setq vars2 (cdr vars2)))
  185. ;; Hash our value into the first context that produced useful results.
  186. (when (and vars firstusefulstart)
  187. (let ((end (save-excursion
  188. (goto-char firstusefulstart)
  189. (save-excursion
  190. (unless (semantic-end-of-context)
  191. (point))))))
  192. ;;(message "Caching values %d->%d." firstusefulstart end)
  193. (semantic-cache-data-to-buffer
  194. (current-buffer) firstusefulstart
  195. (or end
  196. ;; If the end-of-context fails,
  197. ;; just use our cursor starting
  198. ;; position.
  199. start)
  200. vars 'get-local-variables 'exit-cache-zone))
  201. )
  202. ;; Return our list.
  203. vars)))))
  204. (define-overloadable-function semantic-get-local-arguments (&optional point)
  205. "Get arguments (variables) from the current context at POINT.
  206. Parameters are available if the point is in a function or method.
  207. Return a list of tags unlinked from the originating buffer.
  208. Arguments are obtained by overriding `get-local-arguments', or by the
  209. default function `semantic-get-local-arguments-default'. This, must
  210. return a list of tags, or a list of strings that will be converted to
  211. tags."
  212. (save-excursion
  213. (if point (goto-char point))
  214. (let* ((case-fold-search semantic-case-fold)
  215. (args (:override-with-args ()))
  216. arg tags)
  217. ;; Convert unsafe arguments to the right thing.
  218. (while args
  219. (setq arg (car args)
  220. args (cdr args)
  221. tags (cons (cond
  222. ((semantic-tag-p arg)
  223. ;; Return a copy of tag without overlay.
  224. ;; The overlay is preserved.
  225. (semantic-tag-copy arg nil t))
  226. ((stringp arg)
  227. (semantic--tag-put-property
  228. (semantic-tag-new-variable arg nil nil)
  229. :filename (buffer-file-name)))
  230. (t
  231. (error "Unknown parameter element %S" arg)))
  232. tags)))
  233. (nreverse tags))))
  234. (defun semantic-get-local-arguments-default ()
  235. "Get arguments (variables) from the current context.
  236. Parameters are available if the point is in a function or method."
  237. (let ((tag (semantic-current-tag)))
  238. (if (and tag (semantic-tag-of-class-p tag 'function))
  239. (semantic-tag-function-arguments tag))))
  240. (define-overloadable-function semantic-get-all-local-variables (&optional point)
  241. "Get all local variables for this context, and parent contexts.
  242. Local variables are returned in Semantic tag format.
  243. Be default, this gets local variables, and local arguments.
  244. Optional argument POINT is the location to start getting the variables from.")
  245. (defun semantic-get-all-local-variables-default (&optional point)
  246. "Get all local variables for this context.
  247. Optional argument POINT is the location to start getting the variables from.
  248. That is a cons (LOCAL-ARGUMENTS . LOCAL-VARIABLES) where:
  249. - LOCAL-ARGUMENTS is collected by `semantic-get-local-arguments'.
  250. - LOCAL-VARIABLES is collected by `semantic-get-local-variables'."
  251. (save-excursion
  252. (if point (goto-char point))
  253. (let ((case-fold-search semantic-case-fold))
  254. (append (semantic-get-local-arguments)
  255. (semantic-get-local-variables)))))
  256. ;;; Local context parsing
  257. ;;
  258. ;; Context parsing assumes a series of language independent commonalities.
  259. ;; These terms are used to describe those contexts:
  260. ;;
  261. ;; command - One command in the language.
  262. ;; symbol - The symbol the cursor is on.
  263. ;; This would include a series of type/field when applicable.
  264. ;; assignment - The variable currently being assigned to
  265. ;; function - The function call the cursor is on/in
  266. ;; argument - The index to the argument the cursor is on.
  267. ;;
  268. ;;
  269. (define-overloadable-function semantic-end-of-command ()
  270. "Move to the end of the current command.
  271. Be default, uses `semantic-command-separation-character'.")
  272. (defun semantic-end-of-command-default ()
  273. "Move to the end of the current command.
  274. Depends on `semantic-command-separation-character' to find the
  275. beginning and end of a command."
  276. (semantic-with-buffer-narrowed-to-context
  277. (let ((case-fold-search semantic-case-fold))
  278. (with-syntax-table semantic-lex-syntax-table
  279. (if (re-search-forward (regexp-quote semantic-command-separation-character)
  280. nil t)
  281. (forward-char -1)
  282. ;; If there wasn't a command after this, we are the last
  283. ;; command, and we are incomplete.
  284. (goto-char (point-max)))))))
  285. (define-overloadable-function semantic-beginning-of-command ()
  286. "Move to the beginning of the current command.
  287. Be default, uses `semantic-command-separation-character'.")
  288. (defun semantic-beginning-of-command-default ()
  289. "Move to the beginning of the current command.
  290. Depends on `semantic-command-separation-character' to find the
  291. beginning and end of a command."
  292. (semantic-with-buffer-narrowed-to-context
  293. (with-syntax-table semantic-lex-syntax-table
  294. (let ((case-fold-search semantic-case-fold))
  295. (skip-chars-backward semantic-command-separation-character)
  296. (if (re-search-backward (regexp-quote semantic-command-separation-character)
  297. nil t)
  298. (goto-char (match-end 0))
  299. ;; If there wasn't a command after this, we are the last
  300. ;; command, and we are incomplete.
  301. (goto-char (point-min)))
  302. (skip-chars-forward " \t\n")
  303. ))))
  304. (defsubst semantic-point-at-beginning-of-command ()
  305. "Return the point at the beginning of the current command."
  306. (save-excursion (semantic-beginning-of-command) (point)))
  307. (defsubst semantic-point-at-end-of-command ()
  308. "Return the point at the beginning of the current command."
  309. (save-excursion (semantic-end-of-command) (point)))
  310. (defsubst semantic-narrow-to-command ()
  311. "Narrow the current buffer to the current command."
  312. (narrow-to-region (semantic-point-at-beginning-of-command)
  313. (semantic-point-at-end-of-command)))
  314. (defmacro semantic-with-buffer-narrowed-to-command (&rest body)
  315. "Execute BODY with the buffer narrowed to the current command."
  316. `(save-restriction
  317. (semantic-narrow-to-command)
  318. ,@body))
  319. (put 'semantic-with-buffer-narrowed-to-command 'lisp-indent-function 0)
  320. (add-hook 'edebug-setup-hook
  321. (lambda ()
  322. (def-edebug-spec semantic-with-buffer-narrowed-to-command
  323. (def-body))))
  324. (define-overloadable-function semantic-ctxt-current-symbol (&optional point)
  325. "Return the current symbol the cursor is on at POINT in a list.
  326. The symbol includes all logical parts of a complex reference.
  327. For example, in C the statement:
  328. this.that().entry
  329. Would be object `this' calling method `that' which returns some structure
  330. whose field `entry' is being reference. In this case, this function
  331. would return the list:
  332. ( \"this\" \"that\" \"entry\" )")
  333. (defun semantic-ctxt-current-symbol-default (&optional point)
  334. "Return the current symbol the cursor is on at POINT in a list.
  335. This will include a list of type/field names when applicable.
  336. Depends on `semantic-type-relation-separator-character'."
  337. (save-excursion
  338. (if point (goto-char point))
  339. (let* ((fieldsep1 (mapconcat (lambda (a) (regexp-quote a))
  340. semantic-type-relation-separator-character
  341. "\\|"))
  342. ;; NOTE: The [ \n] expression below should used \\s-, but that
  343. ;; doesn't work in C since \n means end-of-comment, and isn't
  344. ;; really whitespace.
  345. (fieldsep (concat "[ \t\n\r]*\\(" fieldsep1 "\\)[ \t\n\r]*\\(\\w\\|\\s_\\)"))
  346. (case-fold-search semantic-case-fold)
  347. (symlist nil)
  348. end)
  349. (with-syntax-table semantic-lex-syntax-table
  350. (save-excursion
  351. (cond ((looking-at "\\w\\|\\s_")
  352. ;; In the middle of a symbol, move to the end.
  353. (forward-sexp 1))
  354. ((looking-at fieldsep1)
  355. ;; We are in a find spot.. do nothing.
  356. nil
  357. )
  358. ((save-excursion
  359. (and (condition-case nil
  360. (progn (forward-sexp -1)
  361. (forward-sexp 1)
  362. t)
  363. (error nil))
  364. (looking-at fieldsep1)))
  365. (setq symlist (list ""))
  366. (forward-sexp -1)
  367. ;; Skip array expressions.
  368. (while (looking-at "\\s(") (forward-sexp -1))
  369. (forward-sexp 1))
  370. )
  371. ;; Set our end point.
  372. (setq end (point))
  373. ;; Now that we have gotten started, let's do the rest.
  374. (condition-case nil
  375. (while (save-excursion
  376. (forward-char -1)
  377. (looking-at "\\w\\|\\s_"))
  378. ;; We have a symbol.. Do symbol things
  379. (forward-sexp -1)
  380. (setq symlist (cons (buffer-substring-no-properties (point) end)
  381. symlist))
  382. ;; Skip the next syntactic expression backwards, then go forwards.
  383. (let ((cp (point)))
  384. (forward-sexp -1)
  385. (forward-sexp 1)
  386. ;; If we end up at the same place we started, we are at the
  387. ;; beginning of a buffer, or narrowed to a command and
  388. ;; have to stop.
  389. (if (<= cp (point)) (error nil)))
  390. (if (looking-at fieldsep)
  391. (progn
  392. (forward-sexp -1)
  393. ;; Skip array expressions.
  394. (while (and (looking-at "\\s(") (not (bobp)))
  395. (forward-sexp -1))
  396. (forward-sexp 1)
  397. (setq end (point)))
  398. (error nil))
  399. )
  400. (error nil)))
  401. symlist))))
  402. (define-overloadable-function semantic-ctxt-current-symbol-and-bounds (&optional point)
  403. "Return the current symbol and bounds the cursor is on at POINT.
  404. The symbol should be the same as returned by `semantic-ctxt-current-symbol'.
  405. Return (PREFIX ENDSYM BOUNDS).")
  406. (defun semantic-ctxt-current-symbol-and-bounds-default (&optional point)
  407. "Return the current symbol and bounds the cursor is on at POINT.
  408. Uses `semantic-ctxt-current-symbol' to calculate the symbol.
  409. Return (PREFIX ENDSYM BOUNDS)."
  410. (save-excursion
  411. (when point (goto-char (point)))
  412. (let* ((prefix (semantic-ctxt-current-symbol))
  413. (endsym (car (reverse prefix)))
  414. ;; @todo - Can we get this data direct from ctxt-current-symbol?
  415. (bounds (save-excursion
  416. (cond ((string= endsym "")
  417. (cons (point) (point))
  418. )
  419. ((and prefix (looking-at endsym))
  420. (cons (point) (progn
  421. (condition-case nil
  422. (forward-sexp 1)
  423. (error nil))
  424. (point))))
  425. (prefix
  426. (condition-case nil
  427. (cons (progn (forward-sexp -1) (point))
  428. (progn (forward-sexp 1) (point)))
  429. (error nil)))
  430. (t nil))))
  431. )
  432. (list prefix endsym bounds))))
  433. (define-overloadable-function semantic-ctxt-current-assignment (&optional point)
  434. "Return the current assignment near the cursor at POINT.
  435. Return a list as per `semantic-ctxt-current-symbol'.
  436. Return nil if there is nothing relevant.")
  437. (defun semantic-ctxt-current-assignment-default (&optional point)
  438. "Return the current assignment near the cursor at POINT.
  439. By default, assume that \"=\" indicates an assignment."
  440. (if point (goto-char point))
  441. (let ((case-fold-search semantic-case-fold))
  442. (with-syntax-table semantic-lex-syntax-table
  443. (condition-case nil
  444. (semantic-with-buffer-narrowed-to-command
  445. (save-excursion
  446. (skip-chars-forward " \t=")
  447. (condition-case nil (forward-char 1) (error nil))
  448. (re-search-backward "[^=]=\\([^=]\\|$\\)")
  449. ;; We are at an equals sign. Go backwards a sexp, and
  450. ;; we'll have the variable. Otherwise we threw an error
  451. (forward-sexp -1)
  452. (semantic-ctxt-current-symbol)))
  453. (error nil)))))
  454. (define-overloadable-function semantic-ctxt-current-function (&optional point)
  455. "Return the current function call the cursor is in at POINT.
  456. The function returned is the one accepting the arguments that
  457. the cursor is currently in. It will not return function symbol if the
  458. cursor is on the text representing that function.")
  459. (defun semantic-ctxt-current-function-default (&optional point)
  460. "Return the current function call the cursor is in at POINT.
  461. The call will be identified for C like languages with the form
  462. NAME ( args ... )"
  463. (if point (goto-char point))
  464. (let ((case-fold-search semantic-case-fold))
  465. (with-syntax-table semantic-lex-syntax-table
  466. (save-excursion
  467. (semantic-up-context)
  468. (when (looking-at "(")
  469. (semantic-ctxt-current-symbol))))
  470. ))
  471. (define-overloadable-function semantic-ctxt-current-argument (&optional point)
  472. "Return the index of the argument position the cursor is on at POINT.")
  473. (defun semantic-ctxt-current-argument-default (&optional point)
  474. "Return the index of the argument the cursor is on at POINT.
  475. Depends on `semantic-function-argument-separation-character'."
  476. (if point (goto-char point))
  477. (let ((case-fold-search semantic-case-fold))
  478. (with-syntax-table semantic-lex-syntax-table
  479. (when (semantic-ctxt-current-function)
  480. (save-excursion
  481. ;; Only get the current arg index if we are in function args.
  482. (let ((p (point))
  483. (idx 1))
  484. (semantic-up-context)
  485. (while (re-search-forward
  486. (regexp-quote semantic-function-argument-separation-character)
  487. p t)
  488. (setq idx (1+ idx)))
  489. idx))))))
  490. (defun semantic-ctxt-current-thing ()
  491. "Calculate a thing identified by the current cursor position.
  492. Calls previously defined `semantic-ctxt-current-...' calls until something
  493. gets a match. See `semantic-ctxt-current-symbol',
  494. `semantic-ctxt-current-function', and `semantic-ctxt-current-assignment'
  495. for details on the return value."
  496. (or (semantic-ctxt-current-symbol)
  497. (semantic-ctxt-current-function)
  498. (semantic-ctxt-current-assignment)))
  499. (define-overloadable-function semantic-ctxt-current-class-list (&optional point)
  500. "Return a list of tag classes that are allowed at POINT.
  501. If POINT is nil, the current buffer location is used.
  502. For example, in Emacs Lisp, the symbol after a ( is most likely
  503. a function. In a makefile, symbols after a : are rules, and symbols
  504. after a $( are variables.")
  505. (defun semantic-ctxt-current-class-list-default (&optional point)
  506. "Return a list of tag classes that are allowed at POINT.
  507. Assume a functional typed language. Uses very simple rules."
  508. (save-excursion
  509. (if point (goto-char point))
  510. (let ((tag (semantic-current-tag)))
  511. (if tag
  512. (cond ((semantic-tag-of-class-p tag 'function)
  513. '(function variable type))
  514. ((or (semantic-tag-of-class-p tag 'type)
  515. (semantic-tag-of-class-p tag 'variable))
  516. '(type))
  517. (t nil))
  518. '(type)
  519. ))))
  520. ;;;###autoload
  521. (define-overloadable-function semantic-ctxt-current-mode (&optional point)
  522. "Return the major mode active at POINT.
  523. POINT defaults to the value of point in current buffer.
  524. You should override this function in multiple mode buffers to
  525. determine which major mode apply at point.")
  526. (defun semantic-ctxt-current-mode-default (&optional point)
  527. "Return the major mode active at POINT.
  528. POINT defaults to the value of point in current buffer.
  529. This default implementation returns the current major mode."
  530. major-mode)
  531. ;;; Scoped Types
  532. ;;
  533. ;; Scoped types are types that the current code would have access to.
  534. ;; The come from the global namespace or from special commands such as "using"
  535. (define-overloadable-function semantic-ctxt-scoped-types (&optional point)
  536. "Return a list of type names currently in scope at POINT.
  537. The return value can be a mixed list of either strings (names of
  538. types that are in scope) or actual tags (type declared locally
  539. that may or may not have a name.)")
  540. (defun semantic-ctxt-scoped-types-default (&optional point)
  541. "Return a list of scoped types by name for the current context at POINT.
  542. This is very different for various languages, and does nothing unless
  543. overridden."
  544. nil)
  545. (define-overloadable-function semantic-ctxt-imported-packages (&optional point)
  546. "Return a list of package tags or names which are being imported at POINT.
  547. The return value is a list of strings which are package names
  548. that are implied in code. Thus a C++ symbol:
  549. foo::bar();
  550. where there is a statement such as:
  551. using baz;
  552. means that the first symbol might be:
  553. baz::foo::bar();"
  554. nil)
  555. (provide 'semantic/ctxt)
  556. ;; Local variables:
  557. ;; generated-autoload-file: "loaddefs.el"
  558. ;; generated-autoload-load-name: "semantic/ctxt"
  559. ;; End:
  560. ;;; semantic/ctxt.el ends here