include.el 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. ;;; semantic/decorate/include.el --- Decoration modes for include statements
  2. ;; Copyright (C) 2008-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <zappo@gnu.org>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;
  17. ;; Highlight any include that is in a state the user may care about.
  18. ;; The basic idea is to have the state be highly visible so users will
  19. ;; as 'what is this?" and get the info they need to fix problems that
  20. ;; are otherwise transparent when trying to get smart completion
  21. ;; working.
  22. (require 'semantic/decorate/mode)
  23. (require 'semantic/db)
  24. (require 'semantic/db-ref)
  25. (require 'semantic/db-find)
  26. (eval-when-compile
  27. (require 'semantic/find))
  28. (defvar semantic-dependency-system-include-path)
  29. (declare-function ede-get-locator-object "ede/files")
  30. (declare-function ede-system-include-path "ede/cpp-root")
  31. ;;; Code:
  32. ;;; FACES AND KEYMAPS
  33. (defvar semantic-decoratiton-mouse-3 (if (featurep 'xemacs) [ button3 ] [ mouse-3 ])
  34. "The keybinding lisp object to use for binding the right mouse button.")
  35. ;;; Includes that are in a happy state!
  36. ;;
  37. (defface semantic-decoration-on-includes
  38. nil
  39. "*Overlay Face used on includes that are not in some other state.
  40. Used by the decoration style: `semantic-decoration-on-includes'."
  41. :group 'semantic-faces)
  42. (defvar semantic-decoration-on-include-map
  43. (let ((km (make-sparse-keymap)))
  44. (define-key km semantic-decoratiton-mouse-3 'semantic-decoration-include-menu)
  45. km)
  46. "Keymap used on includes.")
  47. (defvar semantic-decoration-on-include-menu nil
  48. "Menu used for include headers.")
  49. (easy-menu-define
  50. semantic-decoration-on-include-menu
  51. semantic-decoration-on-include-map
  52. "Include Menu"
  53. (list
  54. "Include"
  55. (semantic-menu-item
  56. ["What Is This?" semantic-decoration-include-describe
  57. :active t
  58. :help "Describe why this include has been marked this way." ])
  59. (semantic-menu-item
  60. ["Visit This Include" semantic-decoration-include-visit
  61. :active t
  62. :help "Visit this include file." ])
  63. "---"
  64. (semantic-menu-item
  65. ["Summarize includes current buffer" semantic-decoration-all-include-summary
  66. :active t
  67. :help "Show a summary for the current buffer containing this include." ])
  68. (semantic-menu-item
  69. ["List found includes (load unparsed)" semanticdb-find-test-translate-path
  70. :active t
  71. :help "List all includes found for this file, and parse unparsed files." ])
  72. (semantic-menu-item
  73. ["List found includes (no loading)" semanticdb-find-test-translate-path-no-loading
  74. :active t
  75. :help "List all includes found for this file, do not parse unparsed files." ])
  76. (semantic-menu-item
  77. ["List all unknown includes" semanticdb-find-adebug-lost-includes
  78. :active t
  79. :help "Show a list of all includes semantic cannot find for this file." ])
  80. "---"
  81. (semantic-menu-item
  82. ["Customize System Include Path" semantic-customize-system-include-path
  83. :active (get 'semantic-dependency-system-include-path major-mode)
  84. :help "Run customize for the system include path for this major mode." ])
  85. (semantic-menu-item
  86. ["Add a System Include Path" semantic-add-system-include
  87. :active t
  88. :help "Add an include path for this session." ])
  89. (semantic-menu-item
  90. ["Remove a System Include Path" semantic-remove-system-include
  91. :active t
  92. :help "Add an include path for this session." ])
  93. ;;["" semantic-decoration-include-
  94. ;; :active t
  95. ;; :help "" ]
  96. ))
  97. ;;; Unknown Includes!
  98. ;;
  99. (defface semantic-decoration-on-unknown-includes
  100. '((((class color) (background dark))
  101. (:background "#900000"))
  102. (((class color) (background light))
  103. (:background "#fff0f0")))
  104. "*Face used to show includes that cannot be found.
  105. Used by the decoration style: `semantic-decoration-on-unknown-includes'."
  106. :group 'semantic-faces)
  107. (defvar semantic-decoration-on-unknown-include-map
  108. (let ((km (make-sparse-keymap)))
  109. ;(define-key km [ mouse-2 ] 'semantic-decoration-unknown-include-describe)
  110. (define-key km semantic-decoratiton-mouse-3 'semantic-decoration-unknown-include-menu)
  111. km)
  112. "Keymap used on unparsed includes.")
  113. (defvar semantic-decoration-on-unknown-include-menu nil
  114. "Menu used for unparsed include headers.")
  115. (easy-menu-define
  116. semantic-decoration-on-unknown-include-menu
  117. semantic-decoration-on-unknown-include-map
  118. "Unknown Include Menu"
  119. (list
  120. "Unknown Include"
  121. (semantic-menu-item
  122. ["What Is This?" semantic-decoration-unknown-include-describe
  123. :active t
  124. :help "Describe why this include has been marked this way." ])
  125. (semantic-menu-item
  126. ["List all unknown includes" semanticdb-find-adebug-lost-includes
  127. :active t
  128. :help "Show a list of all includes semantic cannot find for this file." ])
  129. "---"
  130. (semantic-menu-item
  131. ["Summarize includes current buffer" semantic-decoration-all-include-summary
  132. :active t
  133. :help "Show a summary for the current buffer containing this include." ])
  134. (semantic-menu-item
  135. ["List found includes (load unparsed)" semanticdb-find-test-translate-path
  136. :active t
  137. :help "List all includes found for this file, and parse unparsed files." ])
  138. (semantic-menu-item
  139. ["List found includes (no loading)" semanticdb-find-test-translate-path-no-loading
  140. :active t
  141. :help "List all includes found for this file, do not parse unparsed files." ])
  142. "---"
  143. (semantic-menu-item
  144. ["Customize System Include Path" semantic-customize-system-include-path
  145. :active (get 'semantic-dependency-system-include-path major-mode)
  146. :help "Run customize for the system include path for this major mode." ])
  147. (semantic-menu-item
  148. ["Add a System Include Path" semantic-add-system-include
  149. :active t
  150. :help "Add an include path for this session." ])
  151. (semantic-menu-item
  152. ["Remove a System Include Path" semantic-remove-system-include
  153. :active t
  154. :help "Add an include path for this session." ])
  155. ))
  156. ;;; Includes that need to be parsed.
  157. ;;
  158. (defface semantic-decoration-on-unparsed-includes
  159. '((((class color) (background dark))
  160. (:background "#555500"))
  161. (((class color) (background light))
  162. (:background "#ffff55")))
  163. "*Face used to show includes that have not yet been parsed.
  164. Used by the decoration style: `semantic-decoration-on-unparsed-includes'."
  165. :group 'semantic-faces)
  166. (defvar semantic-decoration-on-unparsed-include-map
  167. (let ((km (make-sparse-keymap)))
  168. (define-key km semantic-decoratiton-mouse-3 'semantic-decoration-unparsed-include-menu)
  169. km)
  170. "Keymap used on unparsed includes.")
  171. (defvar semantic-decoration-on-unparsed-include-menu nil
  172. "Menu used for unparsed include headers.")
  173. (easy-menu-define
  174. semantic-decoration-on-unparsed-include-menu
  175. semantic-decoration-on-unparsed-include-map
  176. "Unparsed Include Menu"
  177. (list
  178. "Unparsed Include"
  179. (semantic-menu-item
  180. ["What Is This?" semantic-decoration-unparsed-include-describe
  181. :active t
  182. :help "Describe why this include has been marked this way." ])
  183. (semantic-menu-item
  184. ["Visit This Include" semantic-decoration-include-visit
  185. :active t
  186. :help "Visit this include file so that header file's tags can be used." ])
  187. (semantic-menu-item
  188. ["Parse This Include" semantic-decoration-unparsed-include-parse-include
  189. :active t
  190. :help "Parse this include file so that header file's tags can be used." ])
  191. (semantic-menu-item
  192. ["Parse All Includes" semantic-decoration-unparsed-include-parse-all-includes
  193. :active t
  194. :help "Parse all the includes so the contents can be used." ])
  195. "---"
  196. (semantic-menu-item
  197. ["Summarize includes current buffer" semantic-decoration-all-include-summary
  198. :active t
  199. :help "Show a summary for the current buffer containing this include." ])
  200. (semantic-menu-item
  201. ["List found includes (load unparsed)" semanticdb-find-test-translate-path
  202. :active t
  203. :help "List all includes found for this file, and parse unparsed files." ])
  204. (semantic-menu-item
  205. ["List found includes (no loading)" semanticdb-find-test-translate-path-no-loading
  206. :active t
  207. :help "List all includes found for this file, do not parse unparsed files." ])
  208. (semantic-menu-item
  209. ["List all unknown includes" semanticdb-find-adebug-lost-includes
  210. :active t
  211. :help "Show a list of all includes semantic cannot find for this file." ])
  212. "---"
  213. (semantic-menu-item
  214. ["Customize System Include Path" semantic-customize-system-include-path
  215. :active (get 'semantic-dependency-system-include-path major-mode)
  216. :help "Run customize for the system include path for this major mode." ])
  217. (semantic-menu-item
  218. ["Add a System Include Path" semantic-add-system-include
  219. :active t
  220. :help "Add an include path for this session." ])
  221. (semantic-menu-item
  222. ["Remove a System Include Path" semantic-remove-system-include
  223. :active t
  224. :help "Add an include path for this session." ])
  225. ;;["" semantic-decoration-unparsed-include-
  226. ;; :active t
  227. ;; :help "" ]
  228. ))
  229. ;;; MODES
  230. ;;; Include statement Decorate Mode
  231. ;;
  232. ;; This mode handles the three states of an include statements
  233. ;;
  234. (define-semantic-decoration-style semantic-decoration-on-includes
  235. "Highlight class members that are includes.
  236. This mode provides a nice context menu on the include statements."
  237. :enabled t)
  238. (defun semantic-decoration-on-includes-p-default (tag)
  239. "Return non-nil if TAG has is an includes that can't be found."
  240. (semantic-tag-of-class-p tag 'include))
  241. (defun semantic-decoration-on-includes-highlight-default (tag)
  242. "Highlight the include TAG to show that semantic can't find it."
  243. (let* ((file (semantic-dependency-tag-file tag))
  244. (table (when file
  245. (semanticdb-file-table-object file t)))
  246. (face nil)
  247. (map nil)
  248. )
  249. (cond
  250. ((not file)
  251. ;; Cannot find this header.
  252. (setq face 'semantic-decoration-on-unknown-includes
  253. map semantic-decoration-on-unknown-include-map)
  254. )
  255. ((and table (number-or-marker-p (oref table pointmax)))
  256. ;; A found and parsed file.
  257. (setq face 'semantic-decoration-on-includes
  258. map semantic-decoration-on-include-map)
  259. )
  260. (t
  261. ;; An unparsed file.
  262. (setq face 'semantic-decoration-on-unparsed-includes
  263. map semantic-decoration-on-unparsed-include-map)
  264. (when table
  265. ;; Set ourselves up for synchronization
  266. (semanticdb-cache-get
  267. table 'semantic-decoration-unparsed-include-cache)
  268. ;; Add a dependency.
  269. (let ((table semanticdb-current-table))
  270. (semanticdb-add-reference table tag))
  271. )
  272. ))
  273. ;; @TODO - if not a tag w/ a position, we need to get one. How?
  274. (when (semantic-tag-with-position-p tag)
  275. (let ((ol (semantic-decorate-tag tag
  276. (semantic-tag-start tag)
  277. (semantic-tag-end tag)
  278. face))
  279. )
  280. (semantic-overlay-put ol 'mouse-face 'highlight)
  281. (semantic-overlay-put ol 'keymap map)
  282. (semantic-overlay-put ol 'help-echo
  283. "Header File : mouse-3 - Context menu")
  284. ))))
  285. ;;; Regular Include Functions
  286. ;;
  287. (defun semantic-decoration-include-describe ()
  288. "Describe what unparsed includes are in the current buffer.
  289. Argument EVENT is the mouse clicked event."
  290. (interactive)
  291. (let* ((tag (or (semantic-current-tag)
  292. (error "No tag under point")))
  293. (file (semantic-dependency-tag-file tag))
  294. (table (when file
  295. (semanticdb-file-table-object file t))))
  296. (with-output-to-temp-buffer (help-buffer) ; "*Help*"
  297. (help-setup-xref (list #'semantic-decoration-include-describe)
  298. (called-interactively-p 'interactive))
  299. (princ "Include File: ")
  300. (princ (semantic-format-tag-name tag nil t))
  301. (princ "\n")
  302. (princ "This include file was found at:\n ")
  303. (princ (semantic-dependency-tag-file tag))
  304. (princ "\n\n")
  305. (princ "Semantic knows where this include file is, and has parsed
  306. its contents.
  307. ")
  308. (let ((inc (semantic-find-tags-by-class 'include table))
  309. (ok 0)
  310. (unknown 0)
  311. (unparsed 0)
  312. (all 0))
  313. (dolist (i inc)
  314. (let* ((fileinner (semantic-dependency-tag-file i))
  315. )
  316. (cond ((not fileinner)
  317. (setq unknown (1+ unknown)))
  318. ((number-or-marker-p (oref table pointmax))
  319. (setq ok (1+ ok)))
  320. (t
  321. (setq unparsed (1+ unparsed))))))
  322. (setq all (+ ok unknown unparsed))
  323. (if (= 0 all)
  324. (princ "There are no other includes in this file.\n")
  325. (princ (format "There are %d more includes in this file.\n"
  326. all))
  327. (princ (format " Unknown Includes: %d\n" unknown))
  328. (princ (format " Unparsed Includes: %d\n" unparsed))
  329. (princ (format " Parsed Includes: %d\n" ok)))
  330. )
  331. ;; Get the semanticdb statement, and display it's contents.
  332. (princ "\nDetails for header file...\n")
  333. (princ "\nMajor Mode: ")
  334. (princ (oref table :major-mode))
  335. (princ "\nTags: ")
  336. (princ (format "%s entries" (length (oref table :tags))))
  337. (princ "\nFile Size: ")
  338. (princ (format "%s chars" (oref table :pointmax)))
  339. (princ "\nSave State: ")
  340. (cond ((oref table dirty)
  341. (princ "Table needs to be saved."))
  342. (t
  343. (princ "Table is saved on disk."))
  344. )
  345. (princ "\nExternal References:")
  346. (dolist (r (oref table db-refs))
  347. (princ "\n ")
  348. (princ (oref r file)))
  349. )))
  350. ;;;###autoload
  351. (defun semantic-decoration-include-visit ()
  352. "Visit the included file at point."
  353. (interactive)
  354. (let ((tag (semantic-current-tag)))
  355. (unless (eq (semantic-tag-class tag) 'include)
  356. (error "Point is not on an include tag"))
  357. (let ((file (semantic-dependency-tag-file tag)))
  358. (cond
  359. ((or (not file) (not (file-exists-p file)))
  360. (error "Could not location include %s"
  361. (semantic-tag-name tag)))
  362. ((get-file-buffer file)
  363. (switch-to-buffer (get-file-buffer file)))
  364. ((stringp file)
  365. (find-file file))
  366. ))))
  367. (defun semantic-decoration-include-menu (event)
  368. "Popup a menu that can help a user understand unparsed includes.
  369. Argument EVENT describes the event that caused this function to be called."
  370. (interactive "e")
  371. (let* ((startwin (selected-window))
  372. (win (semantic-event-window event))
  373. )
  374. (select-window win t)
  375. (save-excursion
  376. ;(goto-char (window-start win))
  377. (mouse-set-point event)
  378. (sit-for 0)
  379. (semantic-popup-menu semantic-decoration-on-include-menu)
  380. )
  381. (select-window startwin)))
  382. ;;; Unknown Include functions
  383. ;;
  384. (defun semantic-decoration-unknown-include-describe ()
  385. "Describe what unknown includes are in the current buffer.
  386. Argument EVENT is the mouse clicked event."
  387. (interactive)
  388. (let ((tag (semantic-current-tag))
  389. (mm major-mode))
  390. (with-output-to-temp-buffer (help-buffer) ; "*Help*"
  391. (help-setup-xref (list #'semantic-decoration-unknown-include-describe)
  392. (called-interactively-p 'interactive))
  393. (princ "Include File: ")
  394. (princ (semantic-format-tag-name tag nil t))
  395. (princ "\n\n")
  396. (princ "This header file has been marked \"Unknown\".
  397. This means that Semantic has not been able to locate this file on disk.
  398. When Semantic cannot find an include file, this means that the
  399. idle summary mode and idle completion modes cannot use the contents of
  400. that file to provide coding assistance.
  401. If this is a system header and you want it excluded from Semantic's
  402. searches (which may be desirable for speed reasons) then you can
  403. safely ignore this state.
  404. If this is a system header, and you want to include it in Semantic's
  405. searches, then you will need to use:
  406. M-x semantic-add-system-include RET /path/to/includes RET
  407. or, in your .emacs file do:
  408. (semantic-add-system-include \"/path/to/include\" '")
  409. (princ (symbol-name mm))
  410. (princ ")
  411. to add the path to Semantic's search.
  412. If this is an include file that belongs to your project, then you may
  413. need to update `semanticdb-project-roots' or better yet, use `ede'
  414. to manage your project. See the ede manual for projects that will
  415. wrap existing project code for Semantic's benefit.
  416. ")
  417. (when (or (eq mm 'c++-mode) (eq mm 'c-mode))
  418. (princ "
  419. For C/C++ includes located within a project, you can use a special
  420. EDE project that will wrap an existing build system. You can do that
  421. like this in your .emacs file:
  422. (ede-cpp-root-project \"NAME\" :file \"FILENAME\" :locate-fcn 'MYFCN)
  423. See the CEDET manual, the EDE manual, or the commentary in
  424. ede/cpp-root.el for more.
  425. If you think this header tag is marked in error, you may need to do:
  426. C-u M-x bovinate RET
  427. to refresh the tags in this buffer, and recalculate the state."))
  428. (princ "
  429. See the Semantic manual node on SemanticDB for more about search paths.")
  430. )))
  431. (defun semantic-decoration-unknown-include-menu (event)
  432. "Popup a menu that can help a user understand unparsed includes.
  433. Argument EVENT describes the event that caused this function to be called."
  434. (interactive "e")
  435. (let* ((startwin (selected-window))
  436. ;; This line has an issue in XEmacs.
  437. (win (semantic-event-window event))
  438. )
  439. (select-window win t)
  440. (save-excursion
  441. ;(goto-char (window-start win))
  442. (mouse-set-point event)
  443. (sit-for 0)
  444. (semantic-popup-menu semantic-decoration-on-unknown-include-menu)
  445. )
  446. (select-window startwin)))
  447. ;;; Interactive parts of unparsed includes
  448. ;;
  449. (defun semantic-decoration-unparsed-include-describe ()
  450. "Describe what unparsed includes are in the current buffer.
  451. Argument EVENT is the mouse clicked event."
  452. (interactive)
  453. (let ((tag (semantic-current-tag)))
  454. (with-output-to-temp-buffer (help-buffer); "*Help*"
  455. (help-setup-xref (list #'semantic-decoration-unparsed-include-describe)
  456. (called-interactively-p 'interactive))
  457. (princ "Include File: ")
  458. (princ (semantic-format-tag-name tag nil t))
  459. (princ "\n")
  460. (princ "This include file was found at:\n ")
  461. (princ (semantic-dependency-tag-file tag))
  462. (princ "\n\n")
  463. (princ "This header file has been marked \"Unparsed\".
  464. This means that Semantic has located this header file on disk
  465. but has not yet opened and parsed this file.
  466. So long as this header file is unparsed, idle summary and
  467. idle completion will not be able to reference the details in this
  468. header.
  469. To resolve this, use the context menu to parse this include file,
  470. or all include files referred to in ")
  471. (princ (buffer-name))
  472. (princ ".
  473. This can take a while in large projects.
  474. Alternately, you can call:
  475. M-x semanticdb-find-test-translate-path RET
  476. to search path Semantic uses to perform completion.
  477. If you think this header tag is marked in error, you may need to do:
  478. C-u M-x bovinate RET
  479. to refresh the tags in this buffer, and recalculate the state.
  480. If you find a repeatable case where a header is marked in error,
  481. report it to cedet-devel@lists.sf.net.") )))
  482. (defun semantic-decoration-unparsed-include-menu (event)
  483. "Popup a menu that can help a user understand unparsed includes.
  484. Argument EVENT describes the event that caused this function to be called."
  485. (interactive "e")
  486. (let* ((startwin (selected-window))
  487. (win (semantic-event-window event))
  488. )
  489. (select-window win t)
  490. (save-excursion
  491. ;(goto-char (window-start win))
  492. (mouse-set-point event)
  493. (sit-for 0)
  494. (semantic-popup-menu semantic-decoration-on-unparsed-include-menu)
  495. )
  496. (select-window startwin)))
  497. (defun semantic-decoration-unparsed-include-parse-include ()
  498. "Parse the include file the user menu-selected from."
  499. (interactive)
  500. (let* ((file (semantic-dependency-tag-file (semantic-current-tag))))
  501. (semanticdb-file-table-object file)
  502. (semantic-decoration-unparsed-include-do-reset)))
  503. (defun semantic-decoration-unparsed-include-parse-all-includes ()
  504. "Parse the include file the user menu-selected from."
  505. (interactive)
  506. (semanticdb-find-translate-path nil nil)
  507. )
  508. ;;; General Includes Information
  509. ;;
  510. (defun semantic-decoration-all-include-summary ()
  511. "Provide a general summary for the state of all includes."
  512. (interactive)
  513. (require 'semantic/dep)
  514. (let* ((table semanticdb-current-table)
  515. (tags (semantic-fetch-tags))
  516. (inc (semantic-find-tags-by-class 'include table))
  517. )
  518. (with-output-to-temp-buffer (help-buffer) ;"*Help*"
  519. (help-setup-xref (list #'semantic-decoration-all-include-summary)
  520. (called-interactively-p 'interactive))
  521. (princ "Include Summary for File: ")
  522. (princ (file-truename (buffer-file-name)))
  523. (princ "\n")
  524. (when (oref table db-refs)
  525. (princ "\nExternal Database References to this buffer:")
  526. (dolist (r (oref table db-refs))
  527. (princ "\n ")
  528. (princ (oref r file)))
  529. )
  530. (princ (format "\nThis file contains %d tags, %d of which are includes.\n"
  531. (length tags) (length inc)))
  532. (let ((ok 0)
  533. (unknown 0)
  534. (unparsed 0)
  535. (all 0))
  536. (dolist (i inc)
  537. (let* ((fileinner (semantic-dependency-tag-file i))
  538. (tableinner (when fileinner
  539. (semanticdb-file-table-object fileinner t))))
  540. (cond ((not fileinner)
  541. (setq unknown (1+ unknown)))
  542. ((number-or-marker-p (oref tableinner pointmax))
  543. (setq ok (1+ ok)))
  544. (t
  545. (setq unparsed (1+ unparsed))))))
  546. (setq all (+ ok unknown unparsed))
  547. (when (not (= 0 all))
  548. (princ (format " Unknown Includes: %d\n" unknown))
  549. (princ (format " Unparsed Includes: %d\n" unparsed))
  550. (princ (format " Parsed Includes: %d\n" ok)))
  551. )
  552. (princ "\nInclude Path Summary:\n\n")
  553. (when (and (boundp 'ede-object)
  554. (boundp 'ede-object-project)
  555. ede-object)
  556. (princ " This file's project include search is handled by the EDE object:\n")
  557. (princ " Buffer Target: ")
  558. (princ (object-print ede-object))
  559. (princ "\n")
  560. (when (not (eq ede-object ede-object-project))
  561. (princ " Buffer Project: ")
  562. (princ (object-print ede-object-project))
  563. (princ "\n")
  564. )
  565. (when ede-object-project
  566. (let ((loc (ede-get-locator-object ede-object-project)))
  567. (princ " Backup in-project Locator: ")
  568. (princ (object-print loc))
  569. (princ "\n")))
  570. (let ((syspath (ede-system-include-path ede-object-project)))
  571. (if (not syspath)
  572. (princ " EDE Project system include path: Empty\n")
  573. (princ " EDE Project system include path:\n")
  574. (dolist (dir syspath)
  575. (princ " ")
  576. (princ dir)
  577. (princ "\n"))
  578. )))
  579. (princ "\n This file's system include path is:\n")
  580. (dolist (dir semantic-dependency-system-include-path)
  581. (princ " ")
  582. (princ dir)
  583. (princ "\n"))
  584. (let ((unk semanticdb-find-lost-includes))
  585. (when unk
  586. (princ "\nAll unknown includes:\n")
  587. (dolist (tag unk)
  588. (princ " ")
  589. (princ (semantic-tag-name tag))
  590. (princ "\n"))
  591. ))
  592. (let* ((semanticdb-find-default-throttle
  593. (if (featurep 'semantic/db-find)
  594. (remq 'unloaded semanticdb-find-default-throttle)
  595. nil))
  596. (path (semanticdb-find-translate-path nil nil)))
  597. (if (<= (length path) (length inc))
  598. (princ "\nThere are currently no includes found recursively.\n")
  599. ;; List the full include list.
  600. (princ "\nSummary of all includes needed by ")
  601. (princ (buffer-name))
  602. (dolist (p path)
  603. (if (slot-boundp p 'tags)
  604. (princ (format "\n %s :\t%d tags, %d are includes. %s"
  605. (object-name-string p)
  606. (length (oref p tags))
  607. (length (semantic-find-tags-by-class
  608. 'include p))
  609. (cond
  610. ((condition-case nil
  611. (oref p dirty)
  612. (error nil))
  613. " dirty.")
  614. ((not (number-or-marker-p (oref table pointmax)))
  615. " Needs to be parsed.")
  616. (t ""))))
  617. (princ (format "\n %s :\tUnparsed"
  618. (object-name-string p))))
  619. )))
  620. )))
  621. ;;; Unparsed Include Features
  622. ;;
  623. ;; This section handles changing states of unparsed include
  624. ;; decorations base on what happens in other files.
  625. ;;
  626. (defclass semantic-decoration-unparsed-include-cache (semanticdb-abstract-cache)
  627. ()
  628. "Class used to reset decorated includes.
  629. When an include's referring file is parsed, we need to undecorate
  630. any decorated referring includes.")
  631. (defmethod semantic-reset ((obj semantic-decoration-unparsed-include-cache))
  632. "Reset OBJ back to it's empty settings."
  633. (let ((table (oref obj table)))
  634. ;; This is a hack. Add in something better?
  635. (semanticdb-notify-references
  636. table (lambda (tab me)
  637. (semantic-decoration-unparsed-include-refrence-reset tab)
  638. ))
  639. ))
  640. (defmethod semanticdb-partial-synchronize ((cache semantic-decoration-unparsed-include-cache)
  641. new-tags)
  642. "Synchronize CACHE with some NEW-TAGS."
  643. (if (semantic-find-tags-by-class 'include new-tags)
  644. (semantic-reset cache)))
  645. (defmethod semanticdb-synchronize ((cache semantic-decoration-unparsed-include-cache)
  646. new-tags)
  647. "Synchronize a CACHE with some NEW-TAGS."
  648. (semantic-reset cache))
  649. (defun semantic-decoration-unparsed-include-refrence-reset (table)
  650. "Refresh any highlighting in buffers referred to by TABLE.
  651. If TABLE is not in a buffer, do nothing."
  652. ;; This cache removal may seem odd in that we are "creating one", but
  653. ;; since we can't get in the fcn unless one exists, this ought to be
  654. ;; ok.
  655. (let ((c (semanticdb-cache-get
  656. table 'semantic-decoration-unparsed-include-cache)))
  657. (semanticdb-cache-remove table c))
  658. (let ((buf (semanticdb-in-buffer-p table)))
  659. (when buf
  660. (semantic-decorate-add-pending-decoration
  661. 'semantic-decoration-unparsed-include-do-reset
  662. buf)
  663. )))
  664. ;;;###autoload
  665. (defun semantic-decoration-unparsed-include-do-reset ()
  666. "Do a reset of unparsed includes in the current buffer."
  667. (let* ((style (assoc "semantic-decoration-on-includes"
  668. semantic-decoration-styles)))
  669. (when (cdr style)
  670. (let ((allinc (semantic-find-tags-included
  671. (semantic-fetch-tags-fast))))
  672. ;; This will do everything, but it should be speedy since it
  673. ;; would have been done once already.
  674. (semantic-decorate-add-decorations allinc)
  675. ))))
  676. (provide 'semantic/decorate/include)
  677. ;; Local variables:
  678. ;; generated-autoload-file: "../loaddefs.el"
  679. ;; generated-autoload-load-name: "semantic/decorate/include"
  680. ;; End:
  681. ;;; semantic/decorate/include.el ends here