Nuke arch-tags.
[emacs.git] / lisp / cedet / semantic / idle.el
blob865315ebe065bd6f80dfb6cd02ca15e72216332c
1 ;;; idle.el --- Schedule parsing tasks in idle time
3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009, 2010, 2011
4 ;; Free Software Foundation, Inc.
6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; Keywords: syntax
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; Originally, `semantic-auto-parse-mode' handled refreshing the
27 ;; tags in a buffer in idle time. Other activities can be scheduled
28 ;; in idle time, all of which require up-to-date tag tables.
29 ;; Having a specialized idle time scheduler that first refreshes
30 ;; the tags buffer, and then enables other idle time tasks reduces
31 ;; the amount of work needed. Any specialized idle tasks need not
32 ;; ask for a fresh tags list.
34 ;; NOTE ON SEMANTIC_ANALYZE
36 ;; Some of the idle modes use the semantic analyzer. The analyzer
37 ;; automatically caches the created context, so it is shared amongst
38 ;; all idle modes that will need it.
40 (require 'semantic)
41 (require 'semantic/ctxt)
42 (require 'semantic/format)
43 (require 'semantic/tag)
44 (require 'timer)
46 ;; For the semantic-find-tags-by-name macro.
47 (eval-when-compile (require 'semantic/find))
49 (defvar eldoc-last-message)
50 (declare-function eldoc-message "eldoc")
51 (declare-function semantic-analyze-interesting-tag "semantic/analyze")
52 (declare-function semantic-analyze-unsplit-name "semantic/analyze/fcn")
53 (declare-function semantic-complete-analyze-inline-idle "semantic/complete")
54 (declare-function semanticdb-deep-find-tags-by-name "semantic/db-find")
55 (declare-function semanticdb-save-all-db-idle "semantic/db")
56 (declare-function semanticdb-typecache-refresh-for-buffer "semantic/db-typecache")
57 (declare-function semantic-decorate-flush-pending-decorations
58 "semantic/decorate/mode")
59 (declare-function pulse-momentary-highlight-region "pulse")
60 (declare-function pulse-momentary-highlight-overlay "pulse")
61 (declare-function semantic-symref-hits-in-region "semantic/symref/filter")
63 ;;; Code:
65 ;;; TIMER RELATED FUNCTIONS
67 (defvar semantic-idle-scheduler-timer nil
68 "Timer used to schedule tasks in idle time.")
70 (defvar semantic-idle-scheduler-work-timer nil
71 "Timer used to schedule tasks in idle time that may take a while.")
73 (defcustom semantic-idle-scheduler-verbose-flag nil
74 "Non-nil means that the idle scheduler should provide debug messages.
75 Use this setting to debug idle activities."
76 :group 'semantic
77 :type 'boolean)
79 (defcustom semantic-idle-scheduler-idle-time 1
80 "Time in seconds of idle before scheduling events.
81 This time should be short enough to ensure that idle-scheduler will be
82 run as soon as Emacs is idle."
83 :group 'semantic
84 :type 'number
85 :set (lambda (sym val)
86 (set-default sym val)
87 (when (timerp semantic-idle-scheduler-timer)
88 (cancel-timer semantic-idle-scheduler-timer)
89 (setq semantic-idle-scheduler-timer nil)
90 (semantic-idle-scheduler-setup-timers))))
92 (defcustom semantic-idle-scheduler-work-idle-time 60
93 "Time in seconds of idle before scheduling big work.
94 This time should be long enough that once any big work is started, it is
95 unlikely the user would be ready to type again right away."
96 :group 'semantic
97 :type 'number
98 :set (lambda (sym val)
99 (set-default sym val)
100 (when (timerp semantic-idle-scheduler-timer)
101 (cancel-timer semantic-idle-scheduler-timer)
102 (setq semantic-idle-scheduler-timer nil)
103 (semantic-idle-scheduler-setup-timers))))
105 (defun semantic-idle-scheduler-setup-timers ()
106 "Lazy initialization of the auto parse idle timer."
107 ;; REFRESH THIS FUNCTION for XEMACS FOIBLES
108 (or (timerp semantic-idle-scheduler-timer)
109 (setq semantic-idle-scheduler-timer
110 (run-with-idle-timer
111 semantic-idle-scheduler-idle-time t
112 #'semantic-idle-scheduler-function)))
113 (or (timerp semantic-idle-scheduler-work-timer)
114 (setq semantic-idle-scheduler-work-timer
115 (run-with-idle-timer
116 semantic-idle-scheduler-work-idle-time t
117 #'semantic-idle-scheduler-work-function)))
120 (defun semantic-idle-scheduler-kill-timer ()
121 "Kill the auto parse idle timer."
122 (if (timerp semantic-idle-scheduler-timer)
123 (cancel-timer semantic-idle-scheduler-timer))
124 (setq semantic-idle-scheduler-timer nil))
127 ;;; MINOR MODE
129 ;; The minor mode portion of this code just sets up the minor mode
130 ;; which does the initial scheduling of the idle timers.
133 (defcustom semantic-idle-scheduler-mode-hook nil
134 "Hook run at the end of the function `semantic-idle-scheduler-mode'."
135 :group 'semantic
136 :type 'hook)
138 (defvar semantic-idle-scheduler-mode nil
139 "Non-nil if idle-scheduler minor mode is enabled.
140 Use the command `semantic-idle-scheduler-mode' to change this variable.")
141 (make-variable-buffer-local 'semantic-idle-scheduler-mode)
143 (defcustom semantic-idle-scheduler-max-buffer-size 0
144 "*Maximum size in bytes of buffers where idle-scheduler is enabled.
145 If this value is less than or equal to 0, idle-scheduler is enabled in
146 all buffers regardless of their size."
147 :group 'semantic
148 :type 'number)
150 (defsubst semantic-idle-scheduler-enabled-p ()
151 "Return non-nil if idle-scheduler is enabled for this buffer.
152 idle-scheduler is disabled when debugging or if the buffer size
153 exceeds the `semantic-idle-scheduler-max-buffer-size' threshold."
154 (and semantic-idle-scheduler-mode
155 (not (and (boundp 'semantic-debug-enabled)
156 semantic-debug-enabled))
157 (not semantic-lex-debug)
158 (or (<= semantic-idle-scheduler-max-buffer-size 0)
159 (< (buffer-size) semantic-idle-scheduler-max-buffer-size))))
161 ;;;###autoload
162 (define-minor-mode semantic-idle-scheduler-mode
163 "Minor mode to auto parse buffer following a change.
164 When this mode is off, a buffer is only rescanned for tokens when
165 some command requests the list of available tokens. When idle-scheduler
166 is enabled, Emacs periodically checks to see if the buffer is out of
167 date, and reparses while the user is idle (not typing.)
169 With prefix argument ARG, turn on if positive, otherwise off. The
170 minor mode can be turned on only if semantic feature is available and
171 the current buffer was set up for parsing. Return non-nil if the
172 minor mode is enabled."
173 nil nil nil
174 (if semantic-idle-scheduler-mode
175 (if (not (and (featurep 'semantic) (semantic-active-p)))
176 (progn
177 ;; Disable minor mode if semantic stuff not available
178 (setq semantic-idle-scheduler-mode nil)
179 (error "Buffer %s was not set up idle time scheduling"
180 (buffer-name)))
181 (semantic-idle-scheduler-setup-timers))))
183 (semantic-add-minor-mode 'semantic-idle-scheduler-mode
184 "ARP")
186 ;;; SERVICES services
188 ;; These are services for managing idle services.
190 (defvar semantic-idle-scheduler-queue nil
191 "List of functions to execute during idle time.
192 These functions will be called in the current buffer after that
193 buffer has had its tags made up to date. These functions
194 will not be called if there are errors parsing the
195 current buffer.")
197 (defun semantic-idle-scheduler-add (function)
198 "Schedule FUNCTION to occur during idle time."
199 (add-to-list 'semantic-idle-scheduler-queue function))
201 (defun semantic-idle-scheduler-remove (function)
202 "Unschedule FUNCTION to occur during idle time."
203 (setq semantic-idle-scheduler-queue
204 (delete function semantic-idle-scheduler-queue)))
206 ;;; IDLE Function
208 (defun semantic-idle-core-handler ()
209 "Core idle function that handles reparsing.
210 And also manages services that depend on tag values."
211 (when semantic-idle-scheduler-verbose-flag
212 (message "IDLE: Core handler..."))
213 (semantic-exit-on-input 'idle-timer
214 (let* ((inhibit-quit nil)
215 (buffers (delq (current-buffer)
216 (delq nil
217 (mapcar #'(lambda (b)
218 (and (buffer-file-name b)
220 (buffer-list)))))
221 safe ;; This safe is not used, but could be.
222 others
223 mode)
224 (when (semantic-idle-scheduler-enabled-p)
225 (save-excursion
226 ;; First, reparse the current buffer.
227 (setq mode major-mode
228 safe (semantic-safe "Idle Parse Error: %S"
229 ;(error "Goofy error 1")
230 (semantic-idle-scheduler-refresh-tags)
233 ;; Now loop over other buffers with same major mode, trying to
234 ;; update them as well. Stop on keypress.
235 (dolist (b buffers)
236 (semantic-throw-on-input 'parsing-mode-buffers)
237 (with-current-buffer b
238 (if (eq major-mode mode)
239 (and (semantic-idle-scheduler-enabled-p)
240 (semantic-safe "Idle Parse Error: %S"
241 ;(error "Goofy error")
242 (semantic-idle-scheduler-refresh-tags)))
243 (push (current-buffer) others))))
244 (setq buffers others))
245 ;; If re-parse of current buffer completed, evaluate all other
246 ;; services. Stop on keypress.
248 ;; NOTE ON COMMENTED SAFE HERE
249 ;; We used to not execute the services if the buffer wsa
250 ;; unparseable. We now assume that they are lexically
251 ;; safe to do, because we have marked the buffer unparseable
252 ;; if there was a problem.
253 ;;(when safe
254 (dolist (service semantic-idle-scheduler-queue)
255 (save-excursion
256 (semantic-throw-on-input 'idle-queue)
257 (when semantic-idle-scheduler-verbose-flag
258 (message "IDLE: execture service %s..." service))
259 (semantic-safe (format "Idle Service Error %s: %%S" service)
260 (funcall service))
261 (when semantic-idle-scheduler-verbose-flag
262 (message "IDLE: execture service %s...done" service))
265 ;; Finally loop over remaining buffers, trying to update them as
266 ;; well. Stop on keypress.
267 (save-excursion
268 (dolist (b buffers)
269 (semantic-throw-on-input 'parsing-other-buffers)
270 (with-current-buffer b
271 (and (semantic-idle-scheduler-enabled-p)
272 (semantic-idle-scheduler-refresh-tags)))))
274 (when semantic-idle-scheduler-verbose-flag
275 (message "IDLE: Core handler...done")))
277 (defun semantic-debug-idle-function ()
278 "Run the Semantic idle function with debugging turned on."
279 (interactive)
280 (let ((debug-on-error t))
281 (semantic-idle-core-handler)
284 (defun semantic-idle-scheduler-function ()
285 "Function run when after `semantic-idle-scheduler-idle-time'.
286 This function will reparse the current buffer, and if successful,
287 call additional functions registered with the timer calls."
288 (when (zerop (recursion-depth))
289 (let ((debug-on-error nil))
290 (save-match-data (semantic-idle-core-handler))
294 ;;; WORK FUNCTION
296 ;; Unlike the shorter timer, the WORK timer will kick of tasks that
297 ;; may take a long time to complete.
298 (defcustom semantic-idle-work-parse-neighboring-files-flag nil
299 "*Non-nil means to parse files in the same dir as the current buffer.
300 Disable to prevent lots of excessive parsing in idle time."
301 :group 'semantic
302 :type 'boolean)
304 (defcustom semantic-idle-work-update-headers-flag nil
305 "*Non-nil means to parse through header files in idle time.
306 Disable to prevent idle time parsing of many files. If completion
307 is called that work will be done then instead."
308 :group 'semantic
309 :type 'boolean)
311 (defun semantic-idle-work-for-one-buffer (buffer)
312 "Do long-processing work for BUFFER.
313 Uses `semantic-safe' and returns the output.
314 Returns t if all processing succeeded."
315 (with-current-buffer buffer
316 (not (and
317 ;; Just in case
318 (semantic-safe "Idle Work Parse Error: %S"
319 (semantic-idle-scheduler-refresh-tags)
322 ;; Option to disable this work.
323 semantic-idle-work-update-headers-flag
325 ;; Force all our include files to get read in so we
326 ;; are ready to provide good smart completion and idle
327 ;; summary information
328 (semantic-safe "Idle Work Including Error: %S"
329 ;; Get the include related path.
330 (when (and (featurep 'semantic/db) (semanticdb-minor-mode-p))
331 (require 'semantic/db-find)
332 (semanticdb-find-translate-path buffer nil)
336 ;; Pre-build the typecaches as needed.
337 (semantic-safe "Idle Work Typecaching Error: %S"
338 (when (featurep 'semantic/db-typecache)
339 (semanticdb-typecache-refresh-for-buffer buffer))
344 (defun semantic-idle-work-core-handler ()
345 "Core handler for idle work processing of long running tasks.
346 Visits Semantic controlled buffers, and makes sure all needed
347 include files have been parsed, and that the typecache is up to date.
348 Uses `semantic-idle-work-for-on-buffer' to do the work."
349 (let ((errbuf nil)
350 (interrupted
351 (semantic-exit-on-input 'idle-work-timer
352 (let* ((inhibit-quit nil)
353 (cb (current-buffer))
354 (buffers (delq (current-buffer)
355 (delq nil
356 (mapcar #'(lambda (b)
357 (and (buffer-file-name b)
359 (buffer-list)))))
360 safe errbuf)
361 ;; First, handle long tasks in the current buffer.
362 (when (semantic-idle-scheduler-enabled-p)
363 (save-excursion
364 (setq safe (semantic-idle-work-for-one-buffer (current-buffer))
366 (when (not safe) (push (current-buffer) errbuf))
368 ;; Now loop over other buffers with same major mode, trying to
369 ;; update them as well. Stop on keypress.
370 (dolist (b buffers)
371 (semantic-throw-on-input 'parsing-mode-buffers)
372 (with-current-buffer b
373 (when (semantic-idle-scheduler-enabled-p)
374 (and (semantic-idle-scheduler-enabled-p)
375 (unless (semantic-idle-work-for-one-buffer (current-buffer))
376 (push (current-buffer) errbuf)))
380 (when (and (featurep 'semantic/db) (semanticdb-minor-mode-p))
381 ;; Save everything.
382 (semanticdb-save-all-db-idle)
384 ;; Parse up files near our active buffer
385 (when semantic-idle-work-parse-neighboring-files-flag
386 (semantic-safe "Idle Work Parse Neighboring Files: %S"
387 (set-buffer cb)
388 (semantic-idle-scheduler-work-parse-neighboring-files))
391 ;; Save everything... again
392 (semanticdb-save-all-db-idle)
395 ;; Done w/ processing
396 nil))))
398 ;; Done
399 (if interrupted
400 "Interrupted"
401 (cond ((not errbuf)
402 "done")
403 ((not (cdr errbuf))
404 (format "done with 1 error in %s" (car errbuf)))
406 (format "done with errors in %d buffers."
407 (length errbuf)))))))
409 (defun semantic-debug-idle-work-function ()
410 "Run the Semantic idle work function with debugging turned on."
411 (interactive)
412 (let ((debug-on-error t))
413 (semantic-idle-work-core-handler)
416 (defun semantic-idle-scheduler-work-function ()
417 "Function run when after `semantic-idle-scheduler-work-idle-time'.
418 This routine handles difficult tasks that require a lot of parsing, such as
419 parsing all the header files used by our active sources, or building up complex
420 datasets."
421 (when semantic-idle-scheduler-verbose-flag
422 (message "Long Work Idle Timer..."))
423 (let ((exit-type (save-match-data
424 (semantic-idle-work-core-handler))))
425 (when semantic-idle-scheduler-verbose-flag
426 (message "Long Work Idle Timer...%s" exit-type)))
429 (defun semantic-idle-scheduler-work-parse-neighboring-files ()
430 "Parse all the files in similar directories to buffers being edited."
431 ;; Lets check to see if EDE matters.
432 (let ((ede-auto-add-method 'never))
433 (dolist (a auto-mode-alist)
434 (when (eq (cdr a) major-mode)
435 (dolist (file (directory-files default-directory t (car a) t))
436 (semantic-throw-on-input 'parsing-mode-buffers)
437 (save-excursion
438 (semanticdb-file-table-object file)
439 ))))
443 ;;; REPARSING
445 ;; Reparsing is installed as semantic idle service.
446 ;; This part ALWAYS happens, and other services occur
447 ;; afterwards.
449 (defvar semantic-before-idle-scheduler-reparse-hook nil
450 "Hook run before option `semantic-idle-scheduler' begins parsing.
451 If any hook function throws an error, this variable is reset to nil.
452 This hook is not protected from lexical errors.")
454 (defvar semantic-after-idle-scheduler-reparse-hook nil
455 "Hook run after option `semantic-idle-scheduler' has parsed.
456 If any hook function throws an error, this variable is reset to nil.
457 This hook is not protected from lexical errors.")
459 (semantic-varalias-obsolete 'semantic-before-idle-scheduler-reparse-hooks
460 'semantic-before-idle-scheduler-reparse-hook "23.2")
461 (semantic-varalias-obsolete 'semantic-after-idle-scheduler-reparse-hooks
462 'semantic-after-idle-scheduler-reparse-hook "23.2")
464 (defun semantic-idle-scheduler-refresh-tags ()
465 "Refreshes the current buffer's tags.
466 This is called by `semantic-idle-scheduler-function' to update the
467 tags in the current buffer.
469 Return non-nil if the refresh was successful.
470 Return nil if there is some sort of syntax error preventing a full
471 reparse.
473 Does nothing if the current buffer doesn't need reparsing."
475 (prog1
476 ;; These checks actually occur in `semantic-fetch-tags', but if we
477 ;; do them here, then all the bovination hooks are not run, and
478 ;; we save lots of time.
479 (cond
480 ;; If the buffer was previously marked unparseable,
481 ;; then don't waste our time.
482 ((semantic-parse-tree-unparseable-p)
483 nil)
484 ;; The parse tree is already ok.
485 ((semantic-parse-tree-up-to-date-p)
488 ;; If the buffer might need a reparse and it is safe to do so,
489 ;; give it a try.
490 (let* (;(semantic-working-type nil)
491 (inhibit-quit nil)
492 ;; (working-use-echo-area-p
493 ;; (not semantic-idle-scheduler-working-in-modeline-flag))
494 ;; (working-status-dynamic-type
495 ;; (if semantic-idle-scheduler-no-working-message
496 ;; nil
497 ;; working-status-dynamic-type))
498 ;; (working-status-percentage-type
499 ;; (if semantic-idle-scheduler-no-working-message
500 ;; nil
501 ;; working-status-percentage-type))
502 (lexically-safe t)
504 ;; Let people hook into this, but don't let them hose
505 ;; us over!
506 (condition-case nil
507 (run-hooks 'semantic-before-idle-scheduler-reparse-hook)
508 (error (setq semantic-before-idle-scheduler-reparse-hook nil)))
510 (unwind-protect
511 ;; Perform the parsing.
512 (progn
513 (when semantic-idle-scheduler-verbose-flag
514 (message "IDLE: reparse %s..." (buffer-name)))
515 (when (semantic-lex-catch-errors idle-scheduler
516 (save-excursion (semantic-fetch-tags))
517 nil)
518 ;; If we are here, it is because the lexical step failed,
519 ;; proably due to unterminated lists or something like that.
521 ;; We do nothing, and just wait for the next idle timer
522 ;; to go off. In the meantime, remember this, and make sure
523 ;; no other idle services can get executed.
524 (setq lexically-safe nil))
525 (when semantic-idle-scheduler-verbose-flag
526 (message "IDLE: reparse %s...done" (buffer-name))))
527 ;; Let people hook into this, but don't let them hose
528 ;; us over!
529 (condition-case nil
530 (run-hooks 'semantic-after-idle-scheduler-reparse-hook)
531 (error (setq semantic-after-idle-scheduler-reparse-hook nil))))
532 ;; Return if we are lexically safe (from prog1)
533 lexically-safe)))
535 ;; After updating the tags, handle any pending decorations for this
536 ;; buffer.
537 (require 'semantic/decorate/mode)
538 (semantic-decorate-flush-pending-decorations (current-buffer))
542 ;;; IDLE SERVICES
544 ;; Idle Services are minor modes which enable or disable a services in
545 ;; the idle scheduler. Creating a new services only requires calling
546 ;; `semantic-create-idle-services' which does all the setup
547 ;; needed to create the minor mode that will enable or disable
548 ;; a services. The services must provide a single function.
550 ;; FIXME doc is incomplete.
551 (defmacro define-semantic-idle-service (name doc &rest forms)
552 "Create a new idle services with NAME.
553 DOC will be a documentation string describing FORMS.
554 FORMS will be called during idle time after the current buffer's
555 semantic tag information has been updated.
556 This routine creates the following functions and variables:"
557 (let ((global (intern (concat "global-" (symbol-name name) "-mode")))
558 (mode (intern (concat (symbol-name name) "-mode")))
559 (hook (intern (concat (symbol-name name) "-mode-hook")))
560 (map (intern (concat (symbol-name name) "-mode-map")))
561 (func (intern (concat (symbol-name name) "-idle-function"))))
563 `(eval-and-compile
564 (define-minor-mode ,global
565 ,(concat "Toggle " (symbol-name global) ".
566 With ARG, turn the minor mode on if ARG is positive, off otherwise.
568 When this minor mode is enabled, `" (symbol-name mode) "' is
569 turned on in every Semantic-supported buffer.")
570 :global t
571 :group 'semantic
572 :group 'semantic-modes
573 :require 'semantic/idle
574 (semantic-toggle-minor-mode-globally
575 ',mode (if ,global 1 -1)))
577 ;; FIXME: Get rid of this when define-minor-mode does it for us.
578 (defcustom ,hook nil
579 ,(concat "Hook run at the end of function `" (symbol-name mode) "'.")
580 :group 'semantic
581 :type 'hook)
583 (defvar ,map
584 (let ((km (make-sparse-keymap)))
586 ,(concat "Keymap for `" (symbol-name mode) "'."))
588 (define-minor-mode ,mode
589 ,doc
590 :keymap ,map
591 (if ,mode
592 (if (not (and (featurep 'semantic) (semantic-active-p)))
593 (progn
594 ;; Disable minor mode if semantic stuff not available
595 (setq ,mode nil)
596 (error "Buffer %s was not set up for parsing"
597 (buffer-name)))
598 ;; Enable the mode mode
599 (semantic-idle-scheduler-add #',func))
600 ;; Disable the mode mode
601 (semantic-idle-scheduler-remove #',func)))
603 (semantic-add-minor-mode ',mode
604 "") ; idle schedulers are quiet?
606 (defun ,func ()
607 ,(concat "Perform idle activity for the minor mode `"
608 (symbol-name mode) "'.")
609 ,@forms))))
610 (put 'define-semantic-idle-service 'lisp-indent-function 1)
613 ;;; SUMMARY MODE
615 ;; A mode similar to eldoc using semantic
616 (defcustom semantic-idle-truncate-long-summaries t
617 "Truncate summaries that are too long to fit in the minibuffer.
618 This can prevent minibuffer resizing in idle time."
619 :group 'semantic
620 :type 'boolean)
622 (defcustom semantic-idle-summary-function
623 'semantic-format-tag-summarize-with-file
624 "Function to call when displaying tag information during idle time.
625 This function should take a single argument, a Semantic tag, and
626 return a string to display.
627 Some useful functions are found in `semantic-format-tag-functions'."
628 :group 'semantic
629 :type semantic-format-tag-custom-list)
631 (defsubst semantic-idle-summary-find-current-symbol-tag (sym)
632 "Search for a semantic tag with name SYM in database tables.
633 Return the tag found or nil if not found.
634 If semanticdb is not in use, use the current buffer only."
635 (car (if (and (featurep 'semantic/db)
636 semanticdb-current-database
637 (require 'semantic/db-find))
638 (cdar (semanticdb-deep-find-tags-by-name sym))
639 (semantic-deep-find-tags-by-name sym (current-buffer)))))
641 (defun semantic-idle-summary-current-symbol-info-brutish ()
642 "Return a string message describing the current context.
643 Gets a symbol with `semantic-ctxt-current-thing' and then
644 tries to find it with a deep targeted search."
645 ;; Try the current "thing".
646 (let ((sym (car (semantic-ctxt-current-thing))))
647 (when sym
648 (semantic-idle-summary-find-current-symbol-tag sym))))
650 (defun semantic-idle-summary-current-symbol-keyword ()
651 "Return a string message describing the current symbol.
652 Returns a value only if it is a keyword."
653 ;; Try the current "thing".
654 (let ((sym (car (semantic-ctxt-current-thing))))
655 (if (and sym (semantic-lex-keyword-p sym))
656 (semantic-lex-keyword-get sym 'summary))))
658 (defun semantic-idle-summary-current-symbol-info-context ()
659 "Return a string message describing the current context.
660 Use the semantic analyzer to find the symbol information."
661 (let ((analysis (condition-case nil
662 (semantic-analyze-current-context (point))
663 (error nil))))
664 (when analysis
665 (require 'semantic/analyze)
666 (semantic-analyze-interesting-tag analysis))))
668 (defun semantic-idle-summary-current-symbol-info-default ()
669 "Return a string message describing the current context.
670 This function will disable loading of previously unloaded files
671 by semanticdb as a time-saving measure."
672 (semanticdb-without-unloaded-file-searches
673 (save-excursion
674 ;; use whichever has success first.
676 (semantic-idle-summary-current-symbol-keyword)
678 (semantic-idle-summary-current-symbol-info-context)
680 (semantic-idle-summary-current-symbol-info-brutish)
681 ))))
683 (defvar semantic-idle-summary-out-of-context-faces
685 font-lock-comment-face
686 font-lock-string-face
687 font-lock-doc-string-face ; XEmacs.
688 font-lock-doc-face ; Emacs 21 and later.
690 "List of font-lock faces that indicate a useless summary context.
691 Those are generally faces used to highlight comments.
693 It might be useful to override this variable to add comment faces
694 specific to a major mode. For example, in jde mode:
696 \(defvar-mode-local jde-mode semantic-idle-summary-out-of-context-faces
697 (append (default-value 'semantic-idle-summary-out-of-context-faces)
698 '(jde-java-font-lock-doc-tag-face
699 jde-java-font-lock-link-face
700 jde-java-font-lock-bold-face
701 jde-java-font-lock-underline-face
702 jde-java-font-lock-pre-face
703 jde-java-font-lock-code-face)))")
705 (defun semantic-idle-summary-useful-context-p ()
706 "Non-nil if we should show a summary based on context."
707 (if (and (boundp 'font-lock-mode)
708 font-lock-mode
709 (memq (get-text-property (point) 'face)
710 semantic-idle-summary-out-of-context-faces))
711 ;; The best I can think of at the moment is to disable
712 ;; in comments by detecting with font-lock.
716 (define-overloadable-function semantic-idle-summary-current-symbol-info ()
717 "Return a string message describing the current context.")
719 (make-obsolete-overload 'semantic-eldoc-current-symbol-info
720 'semantic-idle-summary-current-symbol-info
721 "23.2")
723 (defcustom semantic-idle-summary-mode-hook nil
724 "Hook run at the end of `semantic-idle-summary'."
725 :group 'semantic
726 :type 'hook)
728 (defun semantic-idle-summary-idle-function ()
729 "Display a tag summary of the lexical token under the cursor.
730 Call `semantic-idle-summary-current-symbol-info' for getting the
731 current tag to display information."
732 (or (eq major-mode 'emacs-lisp-mode)
733 (not (semantic-idle-summary-useful-context-p))
734 (let* ((found (semantic-idle-summary-current-symbol-info))
735 (str (cond ((stringp found) found)
736 ((semantic-tag-p found)
737 (funcall semantic-idle-summary-function
738 found nil t)))))
739 ;; Show the message with eldoc functions
740 (unless (and str (boundp 'eldoc-echo-area-use-multiline-p)
741 eldoc-echo-area-use-multiline-p)
742 (let ((w (1- (window-width (minibuffer-window)))))
743 (if (> (length str) w)
744 (setq str (substring str 0 w)))))
745 ;; I borrowed some bits from eldoc to shorten the
746 ;; message.
747 (when semantic-idle-truncate-long-summaries
748 (let ((ea-width (1- (window-width (minibuffer-window))))
749 (strlen (length str)))
750 (when (> strlen ea-width)
751 (setq str (substring str 0 ea-width)))))
752 ;; Display it
753 (eldoc-message str))))
755 (define-minor-mode semantic-idle-summary-mode
756 "Toggle Semantic Idle Summary mode.
757 With ARG, turn Semantic Idle Summary mode on if ARG is positive,
758 off otherwise.
760 When this minor mode is enabled, the echo area displays a summary
761 of the lexical token at point whenever Emacs is idle."
762 :group 'semantic
763 :group 'semantic-modes
764 (if semantic-idle-summary-mode
765 ;; Enable the mode
766 (progn
767 (unless (and (featurep 'semantic) (semantic-active-p))
768 ;; Disable minor mode if semantic stuff not available
769 (setq semantic-idle-summary-mode nil)
770 (error "Buffer %s was not set up for parsing"
771 (buffer-name)))
772 (require 'eldoc)
773 (semantic-idle-scheduler-add 'semantic-idle-summary-idle-function)
774 (add-hook 'pre-command-hook 'semantic-idle-summary-refresh-echo-area t))
775 ;; Disable the mode
776 (semantic-idle-scheduler-remove 'semantic-idle-summary-idle-function)
777 (remove-hook 'pre-command-hook 'semantic-idle-summary-refresh-echo-area t)))
779 (defun semantic-idle-summary-refresh-echo-area ()
780 (and semantic-idle-summary-mode
781 eldoc-last-message
782 (if (and (not executing-kbd-macro)
783 (not (and (boundp 'edebug-active) edebug-active))
784 (not cursor-in-echo-area)
785 (not (eq (selected-window) (minibuffer-window))))
786 (eldoc-message eldoc-last-message)
787 (setq eldoc-last-message nil))))
789 (semantic-add-minor-mode 'semantic-idle-summary-mode "")
791 (define-minor-mode global-semantic-idle-summary-mode
792 "Toggle Global Semantic Idle Summary mode.
793 With ARG, turn Global Semantic Idle Summary mode on if ARG is
794 positive, off otherwise.
796 When this minor mode is enabled, `semantic-idle-summary-mode' is
797 turned on in every Semantic-supported buffer."
798 :global t
799 :group 'semantic
800 :group 'semantic-modes
801 (semantic-toggle-minor-mode-globally
802 'semantic-idle-summary-mode
803 (if global-semantic-idle-summary-mode 1 -1)))
806 ;;; Current symbol highlight
808 ;; This mode will use context analysis to perform highlighting
809 ;; of all uses of the symbol that is under the cursor.
811 ;; This is to mimic the Eclipse tool of a similar nature.
812 (defvar semantic-idle-symbol-highlight-face 'region
813 "Face used for highlighting local symbols.")
815 (defun semantic-idle-symbol-maybe-highlight (tag)
816 "Perhaps add highlighting to the symbol represented by TAG.
817 TAG was found as the symbol under point. If it happens to be
818 visible, then highlight it."
819 (require 'pulse)
820 (let* ((region (when (and (semantic-tag-p tag)
821 (semantic-tag-with-position-p tag))
822 (semantic-tag-overlay tag)))
823 (file (when (and (semantic-tag-p tag)
824 (semantic-tag-with-position-p tag))
825 (semantic-tag-file-name tag)))
826 (buffer (when file (get-file-buffer file)))
827 ;; We use pulse, but we don't want the flashy version,
828 ;; just the stable version.
829 (pulse-flag nil)
831 (cond ((semantic-overlay-p region)
832 (with-current-buffer (semantic-overlay-buffer region)
833 (goto-char (semantic-overlay-start region))
834 (when (pos-visible-in-window-p
835 (point) (get-buffer-window (current-buffer) 'visible))
836 (if (< (semantic-overlay-end region) (point-at-eol))
837 (pulse-momentary-highlight-overlay
838 region semantic-idle-symbol-highlight-face)
839 ;; Not the same
840 (pulse-momentary-highlight-region
841 (semantic-overlay-start region)
842 (point-at-eol)
843 semantic-idle-symbol-highlight-face)))
845 ((vectorp region)
846 (let ((start (aref region 0))
847 (end (aref region 1)))
848 (save-excursion
849 (when buffer (set-buffer buffer))
850 ;; As a vector, we have no filename. Perhaps it is a
851 ;; local variable?
852 (when (and (<= end (point-max))
853 (pos-visible-in-window-p
854 start (get-buffer-window (current-buffer) 'visible)))
855 (goto-char start)
856 (when (re-search-forward
857 (regexp-quote (semantic-tag-name tag))
858 end t)
859 ;; This is likely it, give it a try.
860 (pulse-momentary-highlight-region
861 start (if (<= end (point-at-eol)) end
862 (point-at-eol))
863 semantic-idle-symbol-highlight-face)))
864 ))))
865 nil))
867 (define-semantic-idle-service semantic-idle-local-symbol-highlight
868 "Highlight the tag and symbol references of the symbol under point.
869 Call `semantic-analyze-current-context' to find the reference tag.
870 Call `semantic-symref-hits-in-region' to identify local references."
871 (require 'pulse)
872 (when (semantic-idle-summary-useful-context-p)
873 (let* ((ctxt
874 (semanticdb-without-unloaded-file-searches
875 (semantic-analyze-current-context)))
876 (Hbounds (when ctxt (oref ctxt bounds)))
877 (target (when ctxt (car (reverse (oref ctxt prefix)))))
878 (tag (semantic-current-tag))
879 ;; We use pulse, but we don't want the flashy version,
880 ;; just the stable version.
881 (pulse-flag nil))
882 (when ctxt
883 ;; Highlight the original tag? Protect against problems.
884 (condition-case nil
885 (semantic-idle-symbol-maybe-highlight target)
886 (error nil))
887 ;; Identify all hits in this current tag.
888 (when (semantic-tag-p target)
889 (require 'semantic/symref/filter)
890 (semantic-symref-hits-in-region
891 target (lambda (start end prefix)
892 (when (/= start (car Hbounds))
893 (pulse-momentary-highlight-region
894 start end semantic-idle-symbol-highlight-face))
895 (semantic-throw-on-input 'symref-highlight)
897 (semantic-tag-start tag)
898 (semantic-tag-end tag)))
899 ))))
902 ;;;###autoload
903 (define-minor-mode global-semantic-idle-scheduler-mode
904 "Toggle global use of option `semantic-idle-scheduler-mode'.
905 The idle scheduler will automatically reparse buffers in idle time,
906 and then schedule other jobs setup with `semantic-idle-scheduler-add'.
907 If ARG is positive or nil, enable, if it is negative, disable."
908 :global t
909 :group 'semantic
910 :group 'semantic-modes
911 ;; When turning off, disable other idle modes.
912 (when (null global-semantic-idle-scheduler-mode)
913 (global-semantic-idle-summary-mode -1)
914 (global-semantic-idle-local-symbol-highlight-mode -1)
915 (global-semantic-idle-completions-mode -1))
916 (semantic-toggle-minor-mode-globally
917 'semantic-idle-scheduler-mode
918 (if global-semantic-idle-scheduler-mode 1 -1)))
921 ;;; Completion Popup Mode
923 ;; This mode uses tooltips to display a (hopefully) short list of possible
924 ;; completions available for the text under point. It provides
925 ;; NO provision for actually filling in the values from those completions.
926 (defun semantic-idle-completions-end-of-symbol-p ()
927 "Return non-nil if the cursor is at the END of a symbol.
928 If the cursor is in the middle of a symbol, then we shouldn't be
929 doing fancy completions."
930 (not (looking-at "\\w\\|\\s_")))
932 (defun semantic-idle-completion-list-default ()
933 "Calculate and display a list of completions."
934 (when (and (semantic-idle-summary-useful-context-p)
935 (semantic-idle-completions-end-of-symbol-p))
936 ;; This mode can be fragile. Ignore problems.
937 ;; If something doesn't do what you expect, run
938 ;; the below command by hand instead.
939 (condition-case nil
940 (semanticdb-without-unloaded-file-searches
941 ;; Use idle version.
942 (semantic-complete-analyze-inline-idle)
944 (error nil))
947 (define-semantic-idle-service semantic-idle-completions
948 "Toggle Semantic Idle Completions mode.
949 With ARG, turn Semantic Idle Completions mode on if ARG is
950 positive, off otherwise.
952 This minor mode only takes effect if Semantic is active and
953 `semantic-idle-scheduler-mode' is enabled.
955 When enabled, Emacs displays a list of possible completions at
956 idle time. The method for displaying completions is given by
957 `semantic-complete-inline-analyzer-idle-displayor-class'; the
958 default is to show completions inline.
960 While a completion is displayed, RET accepts the completion; M-n
961 and M-p cycle through completion alternatives; TAB attempts to
962 complete as far as possible, and cycles if no additional
963 completion is possible; and any other command cancels the
964 completion.
966 \\{semantic-complete-inline-map}"
967 ;; Add the ability to override sometime.
968 (semantic-idle-completion-list-default))
971 ;;; Breadcrumbs for tag under point
973 ;; Service that displays a breadcrumbs indication of the tag under
974 ;; point and its parents in the header or mode line.
977 (defcustom semantic-idle-breadcrumbs-display-function
978 #'semantic-idle-breadcrumbs--display-in-header-line
979 "Function to display the tag under point in idle time.
980 This function should take a list of Semantic tags as its only
981 argument. The tags are sorted according to their nesting order,
982 starting with the outermost tag. The function should call
983 `semantic-idle-breadcrumbs-format-tag-list-function' to convert
984 the tag list into a string."
985 :group 'semantic
986 :type '(choice
987 (const :tag "Display in header line"
988 semantic-idle-breadcrumbs--display-in-header-line)
989 (const :tag "Display in mode line"
990 semantic-idle-breadcrumbs--display-in-mode-line)
991 (function :tag "Other function")))
993 (defcustom semantic-idle-breadcrumbs-format-tag-list-function
994 #'semantic-idle-breadcrumbs--format-linear
995 "Function to format the list of tags containing point.
996 This function should take a list of Semantic tags and an optional
997 maximum length of the produced string as its arguments. The
998 maximum length is a hint and can be ignored. When the maximum
999 length is omitted, an unconstrained string should be
1000 produced. The tags are sorted according to their nesting order,
1001 starting with the outermost tag. Single tags should be formatted
1002 using `semantic-idle-breadcrumbs-format-tag-function' unless
1003 special formatting is required."
1004 :group 'semantic
1005 :type '(choice
1006 (const :tag "Format tags as list, innermost last"
1007 semantic-idle-breadcrumbs--format-linear)
1008 (const :tag "Innermost tag with details, followed by remaining tags"
1009 semantic-idle-breadcrumbs--format-innermost-first)
1010 (function :tag "Other function")))
1012 (defcustom semantic-idle-breadcrumbs-format-tag-function
1013 #'semantic-format-tag-abbreviate
1014 "Function to call to format information about tags.
1015 This function should take a single argument, a Semantic tag, and
1016 return a string to display.
1017 Some useful functions are found in `semantic-format-tag-functions'."
1018 :group 'semantic
1019 :type semantic-format-tag-custom-list)
1021 (defcustom semantic-idle-breadcrumbs-separator 'mode-specific
1022 "Specify how to separate tags in the breadcrumbs string.
1023 An arbitrary string or a mode-specific scope nesting
1024 string (like, for example, \"::\" in C++, or \".\" in Java) can
1025 be used."
1026 :group 'semantic
1027 :type '(choice
1028 (const :tag "Use mode specific separator"
1029 mode-specific)
1030 (string :tag "Specify separator string")))
1032 (defcustom semantic-idle-breadcrumbs-header-line-prefix
1033 semantic-stickyfunc-indent-string ;; TODO not optimal
1034 "String used to indent the breadcrumbs string.
1035 Customize this string to match the space used by scrollbars and
1036 fringe."
1037 :group 'semantic
1038 :type 'string)
1040 (defvar semantic-idle-breadcrumbs-popup-menu nil
1041 "Menu used when a tag displayed by `semantic-idle-breadcrumbs-mode' is clicked.")
1043 (defun semantic-idle-breadcrumbs--popup-menu (event)
1044 "Popup a menu that displays things to do to the clicked tag.
1045 Argument EVENT describes the event that caused this function to
1046 be called."
1047 (interactive "e")
1048 (let ((old-window (selected-window))
1049 (window (semantic-event-window event)))
1050 (select-window window t)
1051 (semantic-popup-menu semantic-idle-breadcrumbs-popup-menu)
1052 (select-window old-window)))
1054 (defmacro semantic-idle-breadcrumbs--tag-function (function)
1055 "Return lambda expression calling FUNCTION when called from a popup."
1056 `(lambda (event)
1057 (interactive "e")
1058 (let* ((old-window (selected-window))
1059 (window (semantic-event-window event))
1060 (column (car (nth 6 (nth 1 event)))) ;; TODO semantic-event-column?
1061 (tag (progn
1062 (select-window window t)
1063 (plist-get
1064 (text-properties-at column header-line-format)
1065 'tag))))
1066 (,function tag)
1067 (select-window old-window)))
1070 ;; TODO does this work for mode-line case?
1071 (defvar semantic-idle-breadcrumbs-popup-map
1072 (let ((map (make-sparse-keymap)))
1073 ;; mouse-1 goes to clicked tag
1074 (define-key map
1075 [ header-line mouse-1 ]
1076 (semantic-idle-breadcrumbs--tag-function
1077 semantic-go-to-tag))
1078 ;; mouse-3 pops up a context menu
1079 (define-key map
1080 [ header-line mouse-3 ]
1081 'semantic-idle-breadcrumbs--popup-menu)
1082 map)
1083 "Keymap for semantic idle breadcrumbs minor mode.")
1085 (easy-menu-define
1086 semantic-idle-breadcrumbs-popup-menu
1087 semantic-idle-breadcrumbs-popup-map
1088 "Semantic Breadcrumbs Mode Menu"
1089 (list
1090 "Breadcrumb Tag"
1091 (semantic-menu-item
1092 (vector
1093 "Go to Tag"
1094 (semantic-idle-breadcrumbs--tag-function
1095 semantic-go-to-tag)
1096 :active t
1097 :help "Jump to this tag"))
1098 ;; TODO these entries need minor changes (optional tag argument) in
1099 ;; senator-copy-tag etc
1100 ;; (semantic-menu-item
1101 ;; (vector
1102 ;; "Copy Tag"
1103 ;; (semantic-idle-breadcrumbs--tag-function
1104 ;; senator-copy-tag)
1105 ;; :active t
1106 ;; :help "Copy this tag"))
1107 ;; (semantic-menu-item
1108 ;; (vector
1109 ;; "Kill Tag"
1110 ;; (semantic-idle-breadcrumbs--tag-function
1111 ;; senator-kill-tag)
1112 ;; :active t
1113 ;; :help "Kill tag text to the kill ring, and copy the tag to
1114 ;; the tag ring"))
1115 ;; (semantic-menu-item
1116 ;; (vector
1117 ;; "Copy Tag to Register"
1118 ;; (semantic-idle-breadcrumbs--tag-function
1119 ;; senator-copy-tag-to-register)
1120 ;; :active t
1121 ;; :help "Copy this tag"))
1122 ;; (semantic-menu-item
1123 ;; (vector
1124 ;; "Narrow to Tag"
1125 ;; (semantic-idle-breadcrumbs--tag-function
1126 ;; senator-narrow-to-defun)
1127 ;; :active t
1128 ;; :help "Narrow to the bounds of the current tag"))
1129 ;; (semantic-menu-item
1130 ;; (vector
1131 ;; "Fold Tag"
1132 ;; (semantic-idle-breadcrumbs--tag-function
1133 ;; senator-fold-tag-toggle)
1134 ;; :active t
1135 ;; :style 'toggle
1136 ;; :selected '(let ((tag (semantic-current-tag)))
1137 ;; (and tag (semantic-tag-folded-p tag)))
1138 ;; :help "Fold the current tag to one line"))
1139 "---"
1140 (semantic-menu-item
1141 (vector
1142 "About this Header Line"
1143 (lambda ()
1144 (interactive)
1145 (describe-function 'semantic-idle-breadcrumbs-mode))
1146 :active t
1147 :help "Display help about this header line."))
1151 (define-semantic-idle-service semantic-idle-breadcrumbs
1152 "Display breadcrumbs for the tag under point and its parents."
1153 (let* ((scope (semantic-calculate-scope))
1154 (tag-list (if scope
1155 ;; If there is a scope, extract the tag and its
1156 ;; parents.
1157 (append (oref scope parents)
1158 (when (oref scope tag)
1159 (list (oref scope tag))))
1160 ;; Fall back to tags by overlay
1161 (semantic-find-tag-by-overlay))))
1162 ;; Display the tags.
1163 (funcall semantic-idle-breadcrumbs-display-function tag-list)))
1165 (defun semantic-idle-breadcrumbs--display-in-header-line (tag-list)
1166 "Display the tags in TAG-LIST in the header line of their buffer."
1167 (let ((width (- (nth 2 (window-edges))
1168 (nth 0 (window-edges)))))
1169 ;; Format TAG-LIST and put the formatted string into the header
1170 ;; line.
1171 (setq header-line-format
1172 (concat
1173 semantic-idle-breadcrumbs-header-line-prefix
1174 (if tag-list
1175 (semantic-idle-breadcrumbs--format-tag-list
1176 tag-list
1177 (- width
1178 (length semantic-idle-breadcrumbs-header-line-prefix)))
1179 (propertize
1180 "<not on tags>"
1181 'face
1182 'font-lock-comment-face)))))
1184 ;; Update the header line.
1185 (force-mode-line-update))
1187 (defun semantic-idle-breadcrumbs--display-in-mode-line (tag-list)
1188 "Display the tags in TAG-LIST in the mode line of their buffer.
1189 TODO THIS FUNCTION DOES NOT WORK YET."
1191 (error "This function does not work yet")
1193 (let ((width (- (nth 2 (window-edges))
1194 (nth 0 (window-edges)))))
1195 (setq mode-line-format
1196 (semantic-idle-breadcrumbs--format-tag-list tag-list width)))
1198 (force-mode-line-update))
1200 (defun semantic-idle-breadcrumbs--format-tag-list (tag-list max-length)
1201 "Format TAG-LIST using configured functions respecting MAX-LENGTH.
1202 If the initial formatting result is longer than MAX-LENGTH, it is
1203 shortened at the beginning."
1204 ;; Format TAG-LIST using the configured formatting function.
1205 (let* ((complete-format (funcall
1206 semantic-idle-breadcrumbs-format-tag-list-function
1207 tag-list max-length))
1208 ;; Determine length of complete format.
1209 (complete-length (length complete-format)))
1210 ;; Shorten string if necessary.
1211 (if (<= complete-length max-length)
1212 complete-format
1213 (concat "... "
1214 (substring
1215 complete-format
1216 (- complete-length (- max-length 4))))))
1219 (defun semantic-idle-breadcrumbs--format-linear
1220 (tag-list &optional max-length)
1221 "Format TAG-LIST as a linear list, starting with the outermost tag.
1222 MAX-LENGTH is not used."
1223 (require 'semantic/analyze/fcn)
1224 (let* ((format-pieces (mapcar
1225 #'semantic-idle-breadcrumbs--format-tag
1226 tag-list))
1227 ;; Format tag list, putting configured separators between the
1228 ;; tags.
1229 (complete-format (cond
1230 ;; Mode specific separator.
1231 ((eq semantic-idle-breadcrumbs-separator
1232 'mode-specific)
1233 (semantic-analyze-unsplit-name format-pieces))
1235 ;; Custom separator.
1236 ((stringp semantic-idle-breadcrumbs-separator)
1237 (mapconcat
1238 #'identity
1239 format-pieces
1240 semantic-idle-breadcrumbs-separator)))))
1241 complete-format)
1244 (defun semantic-idle-breadcrumbs--format-innermost-first
1245 (tag-list &optional max-length)
1246 "Format TAG-LIST placing the innermost tag first, separated from its parents.
1247 If MAX-LENGTH is non-nil, the innermost tag is shortened."
1248 (let* (;; Separate and format remaining tags. Calculate length of
1249 ;; resulting string.
1250 (rest-tags (butlast tag-list))
1251 (rest-format (if rest-tags
1252 (concat
1253 " | "
1254 (semantic-idle-breadcrumbs--format-linear
1255 rest-tags))
1256 ""))
1257 (rest-length (length rest-format))
1258 ;; Format innermost tag and calculate length of resulting
1259 ;; string.
1260 (inner-format (semantic-idle-breadcrumbs--format-tag
1261 (car (last tag-list))
1262 #'semantic-format-tag-prototype))
1263 (inner-length (length inner-format))
1264 ;; Calculate complete length and shorten string for innermost
1265 ;; tag if MAX-LENGTH is non-nil and the complete string is
1266 ;; too long.
1267 (complete-length (+ inner-length rest-length))
1268 (inner-short (if (and max-length
1269 (<= complete-length max-length))
1270 inner-format
1271 (concat (substring
1272 inner-format
1274 (- inner-length
1275 (- complete-length max-length)
1277 " ..."))))
1278 ;; Concat both parts.
1279 (concat inner-short rest-format))
1282 (defun semantic-idle-breadcrumbs--format-tag (tag &optional format-function)
1283 "Format TAG using the configured function or FORMAT-FUNCTION.
1284 This function also adds text properties for help-echo, mouse
1285 highlighting and a keymap."
1286 (let ((formatted (funcall
1287 (or format-function
1288 semantic-idle-breadcrumbs-format-tag-function)
1289 tag nil t)))
1290 (add-text-properties
1291 0 (length formatted)
1292 (list
1293 'tag
1295 'help-echo
1296 (format
1297 "Tag %s
1298 Type: %s
1299 mouse-1: jump to tag
1300 mouse-3: popup context menu"
1301 (semantic-tag-name tag)
1302 (semantic-tag-class tag))
1303 'mouse-face
1304 'highlight
1305 'keymap
1306 semantic-idle-breadcrumbs-popup-map)
1307 formatted)
1308 formatted))
1311 (provide 'semantic/idle)
1313 ;; Local variables:
1314 ;; generated-autoload-file: "loaddefs.el"
1315 ;; generated-autoload-load-name: "semantic/idle"
1316 ;; End:
1318 ;;; semantic-idle.el ends here