* lisp/url/url-cache.el (url-is-cached): Doc fix.
[bpt/emacs.git] / lisp / cedet / semantic / texi.el
CommitLineData
55b522b2 1;;; semantic/texi.el --- Semantic details for Texinfo files
9573e58b 2
114f9c96 3;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
9bf6c65c 4;; Free Software Foundation, Inc.
9573e58b
CY
5
6;; Author: Eric M. Ludlam <zappo@gnu.org>
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23;;; Commentary:
24;;
25;; Parse Texinfo buffers using regular expressions. The core parser
26;; engine is the function `semantic-texi-parse-headings'. The
27;; parser plug-in is the function `semantic-texi-parse-region' that
28;; overrides `semantic-parse-region'.
29
30(require 'semantic)
31(require 'semantic/format)
32(require 'texinfo)
33
34(eval-when-compile
35 (require 'semantic/db)
36 (require 'semantic/db-find)
37 (require 'semantic/ctxt)
55b522b2 38 (require 'semantic/find)
abe6fcf1 39 (require 'semantic/doc))
9573e58b 40
a4556861 41(defvar ede-minor-mode)
55b522b2 42(declare-function lookup-words "ispell")
a4556861 43(declare-function ede-current-project "ede")
55b522b2 44
9573e58b
CY
45(defvar semantic-texi-super-regex
46 "^@\\(top\\|chapter\\|\\(sub\\)*section\\|unnumbered\\(\\(sub\\)*sec\\)?\\|\
47\\(chap\\|\\(sub\\)+\\|major\\)?heading\\|appendix\\(\\(sub\\)*sec\\)?\\|\
48centerchap\\|def\\(var\\|un\\|fn\\|opt\\)x?\\)"
49 "Regular expression used to find special sections in a Texinfo file.")
50
51(defvar semantic-texi-name-field-list
52 '( ("defvar" . 1)
53 ("defvarx" . 1)
54 ("defun" . 1)
55 ("defunx" . 1)
56 ("defopt" . 1)
57 ("deffn" . 2)
58 ("deffnx" . 2)
59 )
60 "List of definition commands, and the field position.
61The field position is the field number (based at 1) where the
62name of this section is.")
63
64;;; Code:
65(defun semantic-texi-parse-region (&rest ignore)
66 "Parse the current texinfo buffer for semantic tags.
67IGNORE any arguments, always parse the whole buffer.
68Each tag returned is of the form:
69 (\"NAME\" section (:members CHILDREN))
70or
71 (\"NAME\" def)
72
73It is an override of 'parse-region and must be installed by the
74function `semantic-install-function-overrides'."
75 (mapcar 'semantic-texi-expand-tag
76 (semantic-texi-parse-headings)))
77
78(defun semantic-texi-parse-changes ()
79 "Parse changes in the current texinfo buffer."
80 ;; NOTE: For now, just schedule a full reparse.
81 ;; To be implemented later.
82 (semantic-parse-tree-set-needs-rebuild))
83
84(defun semantic-texi-expand-tag (tag)
85 "Expand the texinfo tag TAG."
86 (let ((chil (semantic-tag-components tag)))
87 (if chil
88 (semantic-tag-put-attribute
89 tag :members (mapcar 'semantic-texi-expand-tag chil)))
90 (car (semantic--tag-expand tag))))
91
92(defun semantic-texi-parse-headings ()
93 "Parse the current texinfo buffer for all semantic tags now."
94 (let ((pass1 nil))
95 ;; First search and snarf.
96 (save-excursion
97 (goto-char (point-min))
98 (let ((semantic--progress-reporter
99 (make-progress-reporter
100 (format "Parsing %s..."
101 (file-name-nondirectory buffer-file-name))
102 (point-min) (point-max))))
103 (while (re-search-forward semantic-texi-super-regex nil t)
104 (setq pass1 (cons (match-beginning 0) pass1))
105 (progress-reporter-update semantic--progress-reporter (point)))
106 (progress-reporter-done semantic--progress-reporter)))
107 (setq pass1 (nreverse pass1))
108 ;; Now, make some tags while creating a set of children.
109 (car (semantic-texi-recursive-combobulate-list pass1 0))
110 ))
111
112(defsubst semantic-texi-new-section-tag (name members start end)
113 "Create a semantic tag of class section.
114NAME is the name of this section.
115MEMBERS is a list of semantic tags representing the elements that make
116up this section.
117START and END define the location of data described by the tag."
118 (append (semantic-tag name 'section :members members)
119 (list start end)))
120
121(defsubst semantic-texi-new-def-tag (name start end)
122 "Create a semantic tag of class def.
123NAME is the name of this definition.
124START and END define the location of data described by the tag."
125 (append (semantic-tag name 'def)
126 (list start end)))
127
128(defun semantic-texi-set-endpoint (metataglist pnt)
129 "Set the end point of the first section tag in METATAGLIST to PNT.
130METATAGLIST is a list of tags in the intermediate tag format used by the
131texinfo parser. PNT is the new point to set."
132 (let ((metatag nil))
133 (while (and metataglist
134 (not (eq (semantic-tag-class (car metataglist)) 'section)))
135 (setq metataglist (cdr metataglist)))
136 (setq metatag (car metataglist))
137 (when metatag
138 (setcar (nthcdr (1- (length metatag)) metatag) pnt)
139 metatag)))
140
141(defun semantic-texi-recursive-combobulate-list (sectionlist level)
142 "Rearrange SECTIONLIST to be a hierarchical tag list starting at LEVEL.
143Return the rearranged new list, with all remaining tags from
144SECTIONLIST starting at ELT 2. Sections not are not dealt with as soon as a
145tag with greater section value than LEVEL is found."
146 (let ((newl nil)
147 (oldl sectionlist)
148 tag
149 )
150 (save-excursion
151 (catch 'level-jump
152 (while oldl
153 (goto-char (car oldl))
154 (if (looking-at "@\\(\\w+\\)")
155 (let* ((word (match-string 1))
156 (levelmatch (assoc word texinfo-section-list))
157 text begin tmp
158 )
159 ;; Set begin to the right location
160 (setq begin (point))
161 ;; Get out of here if there if we made it that far.
162 (if (and levelmatch (<= (car (cdr levelmatch)) level))
163 (progn
164 (when newl
165 (semantic-texi-set-endpoint newl begin))
166 (throw 'level-jump t)))
167 ;; Recombobulate
168 (if levelmatch
169 (let ((end (match-end 1)))
170 ;; Levels sometimes have a @node just in front.
171 ;; That node statement should be included in the space
172 ;; for this entry.
173 (save-excursion
174 (skip-chars-backward "\n \t")
175 (beginning-of-line)
176 (when (looking-at "@node\\>")
177 (setq begin (point))))
178 ;; When there is a match, the descriptive text
179 ;; consists of the rest of the line.
180 (goto-char end)
181 (skip-chars-forward " \t")
182 (setq text (buffer-substring-no-properties
183 (point)
184 (progn (end-of-line) (point))))
185 ;; Next, recurse into the body to find the end.
186 (setq tmp (semantic-texi-recursive-combobulate-list
187 (cdr oldl) (car (cdr levelmatch))))
188 ;; Build a tag
189 (setq tag (semantic-texi-new-section-tag
190 text (car tmp) begin (point)))
191 ;; Before appending the newtag, update the previous tag
192 ;; if it is a section tag.
193 (when newl
194 (semantic-texi-set-endpoint newl begin))
195 ;; Append new tag to our master list.
196 (setq newl (cons tag newl))
197 ;; continue
198 (setq oldl (cdr tmp))
199 )
200 ;; No match means we have a def*, so get the name from
201 ;; it based on the type of thingy we found.
202 (setq levelmatch (assoc word semantic-texi-name-field-list)
203 tmp (or (cdr levelmatch) 1))
204 (forward-sexp tmp)
205 (skip-chars-forward " \t")
206 (setq text (buffer-substring-no-properties
207 (point)
208 (progn (forward-sexp 1) (point))))
209 ;; Seek the end of this definition
210 (goto-char begin)
211 (semantic-texi-forward-deffn)
212 (setq tag (semantic-texi-new-def-tag text begin (point))
213 newl (cons tag newl))
214 ;; continue
215 (setq oldl (cdr oldl)))
216 )
217 (error "Problem finding section in semantic/texi parser"))
218 ;; (setq oldl (cdr oldl))
219 )
220 ;; When oldl runs out, force a new endpoint as point-max
221 (when (not oldl)
222 (semantic-texi-set-endpoint newl (point-max)))
223 ))
224 (cons (nreverse newl) oldl)))
225
226(defun semantic-texi-forward-deffn ()
227 "Move forward over one deffn type definition.
228The cursor should be on the @ sign."
229 (when (looking-at "@\\(\\w+\\)")
230 (let* ((type (match-string 1))
231 (seek (concat "^@end\\s-+" (regexp-quote type))))
232 (re-search-forward seek nil t))))
233
234(define-mode-local-override semantic-tag-components
235 texinfo-mode (tag)
236 "Return components belonging to TAG."
237 (semantic-tag-get-attribute tag :members))
238
239\f
240;;; Overrides: Context Parsing
241;;
242;; How to treat texi as a language?
243;;
244(defvar semantic-texi-environment-regexp
245 (if (string-match texinfo-environment-regexp "@menu")
246 ;; Make sure our Emacs has menus in it.
247 texinfo-environment-regexp
248 ;; If no menus, then merge in the menu concept.
249 (when (string-match "cartouche" texinfo-environment-regexp)
250 (concat (substring texinfo-environment-regexp
251 0 (match-beginning 0))
252 "menu\\|"
253 (substring texinfo-environment-regexp
254 (match-beginning 0)))))
9bf6c65c 255 "Regular expression for matching texinfo environments.
9573e58b
CY
256uses `texinfo-environment-regexp', but makes sure that it
257can handle the @menu environment.")
258
259(define-mode-local-override semantic-up-context texinfo-mode ()
260 "Handle texinfo constructs which do not use parenthetical nesting."
261 (let ((done nil))
262 (save-excursion
263 (let ((parenthetical (semantic-up-context-default))
264 )
265 (when (not parenthetical)
266 ;; We are in parenthises. Are they the types of parens
267 ;; belonging to a texinfo construct?
268 (forward-word -1)
269 (when (looking-at "@\\w+{")
270 (setq done (point))))))
271 ;; If we are not in a parenthetical node, then find a block instead.
272 ;; Use the texinfo support to find block start/end constructs.
273 (save-excursion
274 (while (and (not done)
275 (re-search-backward semantic-texi-environment-regexp nil t))
276 ;; For any hit, if we find an @end foo, then jump to the
277 ;; matching @foo. If it is not an end, then we win!
278 (if (not (looking-at "@end\\s-+\\(\\w+\\)"))
279 (setq done (point))
280 ;; Skip over this block
281 (let ((env (match-string 1)))
282 (re-search-backward (concat "@" env))))
283 ))
284 ;; All over, post what we find.
285 (if done
286 ;; We found something, so use it.
287 (progn (goto-char done)
288 nil)
289 t)))
290
291(define-mode-local-override semantic-beginning-of-context texinfo-mode (&optional point)
292 "Move to the beginning of the context surrounding POINT."
293 (if (semantic-up-context point)
294 ;; If we can't go up, we can't do this either.
295 t
296 ;; We moved, so now we need to skip into whatever this thing is.
297 (forward-word 1) ;; skip the command
298 (if (looking-at "\\s-*{")
299 ;; In a short command. Go in.
300 (down-list 1)
301 ;; An environment. Go to the next line.
302 (end-of-line)
303 (forward-char 1))
304 nil))
305
306(define-mode-local-override semantic-ctxt-current-class-list
307 texinfo-mode (&optional point)
308 "Determine the class of tags that can be used at POINT.
309For texinfo, there two possibilities returned.
3101) 'function - for a call to a texinfo function
3112) 'word - indicates an english word.
312It would be nice to know function arguments too, but not today."
313 (let ((sym (semantic-ctxt-current-symbol)))
314 (if (and sym (= (aref (car sym) 0) ?@))
315 '(function)
316 '(word))))
317
318\f
319;;; Overrides : Formatting
320;;
321;; Various override to better format texi tags.
322;;
323
324(define-mode-local-override semantic-format-tag-abbreviate
325 texinfo-mode (tag &optional parent color)
326 "Texinfo tags abbreviation."
327 (let ((class (semantic-tag-class tag))
328 (name (semantic-format-tag-name tag parent color))
329 )
330 (cond ((eq class 'function)
331 (concat name "{ }"))
332 (t (semantic-format-tag-abbreviate-default tag parent color)))
333 ))
334
335(define-mode-local-override semantic-format-tag-prototype
336 texinfo-mode (tag &optional parent color)
337 "Texinfo tags abbreviation."
338 (semantic-format-tag-abbreviate tag parent color))
339
340\f
341;;; Texi Unique Features
342;;
343(defun semantic-tag-texi-section-text-bounds (tag)
344 "Get the bounds to the text of TAG.
345The text bounds is the text belonging to this node excluding
346the text of any child nodes, but including any defuns."
347 (let ((memb (semantic-tag-components tag)))
348 ;; Members.. if one is a section, check it out.
349 (while (and memb (not (semantic-tag-of-class-p (car memb) 'section)))
350 (setq memb (cdr memb)))
351 ;; No members? ... then a simple problem!
352 (if (not memb)
353 (semantic-tag-bounds tag)
354 ;; Our end is their beginning...
355 (list (semantic-tag-start tag) (semantic-tag-start (car memb))))))
356
357(defun semantic-texi-current-environment (&optional point)
358 "Return as a string the type of the current environment.
359Optional argument POINT is where to look for the environment."
360 (save-excursion
361 (when point (goto-char (point)))
362 (while (and (or (not (looking-at semantic-texi-environment-regexp))
363 (looking-at "@end"))
364 (not (semantic-up-context)))
365 )
366 (when (looking-at semantic-texi-environment-regexp)
367 (match-string 1))))
368
369\f
370;;; Analyzer
371;;
372(eval-when-compile
373 (require 'semantic/analyze))
374
375(define-mode-local-override semantic-analyze-current-context
376 texinfo-mode (point)
377 "Analysis context makes no sense for texinfo. Return nil."
378 (let* ((prefixandbounds (semantic-ctxt-current-symbol-and-bounds (point)))
379 (prefix (car prefixandbounds))
380 (bounds (nth 2 prefixandbounds))
381 (prefixclass (semantic-ctxt-current-class-list))
382 )
383 (when prefix
55b522b2 384 (require 'semantic/analyze)
9573e58b
CY
385 (semantic-analyze-context
386 "Context-for-texinfo"
387 :buffer (current-buffer)
388 :scope nil
389 :bounds bounds
390 :prefix prefix
391 :prefixtypes nil
392 :prefixclass prefixclass)
393 )
394 ))
395
396(defvar semantic-texi-command-completion-list
397 (append (mapcar (lambda (a) (car a)) texinfo-section-list)
398 (condition-case nil
399 texinfo-environments
400 (error
401 ;; XEmacs doesn't use the above. Split up its regexp
402 (split-string texinfo-environment-regexp "\\\\|\\|\\^@\\\\(\\|\\\\)")
403 ))
404 ;; Is there a better list somewhere? Here are few
405 ;; of the top of my head.
406 "anchor" "asis"
407 "bullet"
408 "code" "copyright"
409 "defun" "deffn" "defoption" "defvar" "dfn"
410 "emph" "end"
411 "ifinfo" "iftex" "inforef" "item" "itemx"
412 "kdb"
413 "node"
414 "ref"
415 "set" "setfilename" "settitle"
416 "value" "var"
417 "xref"
418 )
419 "List of commands that we might bother completing.")
420
421(define-mode-local-override semantic-analyze-possible-completions
422 texinfo-mode (context)
423 "List smart completions at point.
424Since texinfo is not a programming language the default version is not
425useful. Insted, look at the current symbol. If it is a command
426do primitive texinfo built ins. If not, use ispell to lookup words
427that start with that symbol."
428 (let ((prefix (car (oref context :prefix)))
429 )
430 (cond ((member 'function (oref context :prefixclass))
431 ;; Do completion for texinfo commands
432 (let* ((cmd (substring prefix 1))
433 (lst (all-completions
434 cmd semantic-texi-command-completion-list)))
435 (mapcar (lambda (f) (semantic-tag (concat "@" f) 'function))
436 lst))
437 )
438 ((member 'word (oref context :prefixclass))
439 ;; Do completion for words via ispell.
440 (require 'ispell)
441 (let ((word-list (lookup-words prefix)))
442 (mapcar (lambda (f) (semantic-tag f 'word)) word-list))
443 )
444 (t nil))
445 ))
446
447\f
448;;; Parser Setup
449;;
f3628edd
GM
450;; In semantic-imenu.el, not part of Emacs.
451(defvar semantic-imenu-expandable-tag-classes)
452(defvar semantic-imenu-bucketize-file)
453(defvar semantic-imenu-bucketize-type-members)
454
9573e58b
CY
455(defun semantic-default-texi-setup ()
456 "Set up a buffer for parsing of Texinfo files."
457 ;; This will use our parser.
458 (semantic-install-function-overrides
459 '((parse-region . semantic-texi-parse-region)
460 (parse-changes . semantic-texi-parse-changes)))
461 (setq semantic-parser-name "TEXI"
462 ;; Setup a dummy parser table to enable parsing!
463 semantic--parse-table t
464 imenu-create-index-function 'semantic-create-imenu-index
465 semantic-command-separation-character "@"
466 semantic-type-relation-separator-character '(":")
467 semantic-symbol->name-assoc-list '((section . "Section")
468 (def . "Definition")
469 )
470 semantic-imenu-expandable-tag-classes '(section)
471 semantic-imenu-bucketize-file nil
472 semantic-imenu-bucketize-type-members nil
473 senator-step-at-start-end-tag-classes '(section)
474 semantic-stickyfunc-sticky-classes '(section)
475 )
996bc9bf 476 ;; (local-set-key [(f9)] 'semantic-texi-update-doc-from-texi)
9573e58b
CY
477 )
478
479(add-hook 'texinfo-mode-hook 'semantic-default-texi-setup)
480
481\f
482;;; Special features of Texinfo tag streams
483;;
484;; This section provides specialized access into texinfo files.
485;; Because texinfo files often directly refer to functions and programs
486;; it is useful to access the texinfo file from the C code for document
487;; maintainance.
488(defun semantic-texi-associated-files (&optional buffer)
489 "Find texinfo files associated with BUFFER."
490 (save-excursion
491 (if buffer (set-buffer buffer))
492 (cond ((and (fboundp 'ede-documentation-files)
493 ede-minor-mode (ede-current-project))
494 ;; When EDE is active, ask it.
495 (ede-documentation-files)
496 )
55b522b2 497 ((and (featurep 'semantic/db) (semanticdb-minor-mode-p))
9573e58b
CY
498 ;; See what texinfo files we have loaded in the database
499 (let ((tabs (semanticdb-get-database-tables
500 semanticdb-current-database))
501 (r nil))
502 (while tabs
503 (if (eq (oref (car tabs) major-mode) 'texinfo-mode)
504 (setq r (cons (oref (car tabs) file) r)))
505 (setq tabs (cdr tabs)))
506 r))
507 (t
508 (directory-files default-directory nil "\\.texi$"))
509 )))
510
511;; Turns out this might not be useful.
512;; Delete later if that is true.
513(defun semantic-texi-find-documentation (name &optional type)
514 "Find the function or variable NAME of TYPE in the texinfo source.
515NAME is a string representing some functional symbol.
516TYPE is a string, such as \"variable\" or \"Command\" used to find
517the correct definition in case NAME qualifies as several things.
518When this function exists, POINT is at the definition.
519If the doc was not found, an error is thrown.
520Note: TYPE not yet implemented."
521 (let ((f (semantic-texi-associated-files))
522 stream match)
523 (while (and f (not match))
524 (unless stream
525 (with-current-buffer (find-file-noselect (car f))
526 (setq stream (semantic-fetch-tags))))
527 (setq match (semantic-find-first-tag-by-name name stream))
528 (when match
529 (set-buffer (semantic-tag-buffer match))
530 (goto-char (semantic-tag-start match)))
531 (setq f (cdr f)))))
532
996bc9bf
CY
533;; (defun semantic-texi-update-doc-from-texi (&optional tag)
534;; "Update the documentation in the texinfo deffn class tag TAG.
535;; The current buffer must be a texinfo file containing TAG.
536;; If TAG is nil, determine a tag based on the current position."
537;; (interactive)
538;; (unless (or (featurep 'semantic/db)
539;; (require 'semantic/db-mode)
540;; (semanticdb-minor-mode-p))
541;; (error "Texinfo updating only works when `semanticdb' is being used"))
542;; (semantic-fetch-tags)
543;; (unless tag
544;; (beginning-of-line)
545;; (setq tag (semantic-current-tag)))
546;; (unless (semantic-tag-of-class-p tag 'def)
547;; (error "Only deffns (or defun or defvar) can be updated"))
548;; (let* ((name (semantic-tag-name tag))
549;; (tags (semanticdb-strip-find-results
550;; (semanticdb-with-match-any-mode
551;; (semanticdb-brute-deep-find-tags-by-name name))
552;; 'name))
553;; (docstring nil)
554;; (docstringproto nil)
555;; (docstringvar nil)
556;; (doctag nil)
557;; (doctagproto nil)
558;; (doctagvar nil)
559;; )
560;; (save-excursion
561;; (while (and tags (not docstring))
562;; (let ((sourcetag (car tags)))
563;; ;; There could be more than one! Come up with a better
564;; ;; solution someday.
565;; (when (semantic-tag-buffer sourcetag)
566;; (set-buffer (semantic-tag-buffer sourcetag))
567;; (unless (eq major-mode 'texinfo-mode)
568;; (cond ((semantic-tag-get-attribute sourcetag :prototype-flag)
569;; ;; If we found a match with doc that is a prototype, then store
570;; ;; that, but don't exit till we find the real deal.
571;; (setq docstringproto (semantic-documentation-for-tag sourcetag)
572;; doctagproto sourcetag))
573;; ((eq (semantic-tag-class sourcetag) 'variable)
574;; (setq docstringvar (semantic-documentation-for-tag sourcetag)
575;; doctagvar sourcetag))
576;; ((semantic-tag-get-attribute sourcetag :override-function-flag)
577;; nil)
578;; (t
579;; (setq docstring (semantic-documentation-for-tag sourcetag))))
580;; (setq doctag (if docstring sourcetag nil))))
581;; (setq tags (cdr tags)))))
582;; ;; If we found a prototype of the function that has some doc, but not the
583;; ;; actual function, lets make due with that.
584;; (if (not docstring)
585;; (cond ((stringp docstringvar)
586;; (setq docstring docstringvar
587;; doctag doctagvar))
588;; ((stringp docstringproto)
589;; (setq docstring docstringproto
590;; doctag doctagproto))))
591;; ;; Test for doc string
592;; (unless docstring
593;; (error "Could not find documentation for %s" (semantic-tag-name tag)))
594;; ;; If we have a string, do the replacement.
595;; (delete-region (semantic-tag-start tag)
596;; (semantic-tag-end tag))
597;; ;; Use useful functions from the docaument library.
598;; (require 'document)
599;; (document-insert-texinfo doctag (semantic-tag-buffer doctag))
600;; ))
601
602;; (defun semantic-texi-update-doc-from-source (&optional tag)
603;; "Update the documentation for the source TAG.
604;; The current buffer must be a non-texinfo source file containing TAG.
605;; If TAG is nil, determine the tag based on the current position.
606;; The current buffer must include TAG."
607;; (interactive)
608;; (when (eq major-mode 'texinfo-mode)
609;; (error "Not a source file"))
610;; (semantic-fetch-tags)
611;; (unless tag
612;; (setq tag (semantic-current-tag)))
613;; (unless (semantic-documentation-for-tag tag)
614;; (error "Cannot find interesting documentation to use for %s"
615;; (semantic-tag-name tag)))
616;; (let* ((name (semantic-tag-name tag))
617;; (texi (semantic-texi-associated-files))
618;; (doctag nil)
619;; (docbuff nil))
620;; (while (and texi (not doctag))
621;; (set-buffer (find-file-noselect (car texi)))
622;; (setq doctag (car (semantic-deep-find-tags-by-name
623;; name (semantic-fetch-tags)))
624;; docbuff (if doctag (current-buffer) nil))
625;; (setq texi (cdr texi)))
626;; (unless doctag
627;; (error "Tag %s is not yet documented. Use the `document' command"
628;; name))
629;; ;; Ok, we should have everything we need. Do the deed.
630;; (if (get-buffer-window docbuff)
631;; (set-buffer docbuff)
632;; (switch-to-buffer docbuff))
633;; (goto-char (semantic-tag-start doctag))
634;; (delete-region (semantic-tag-start doctag)
635;; (semantic-tag-end doctag))
636;; ;; Use useful functions from the document library.
637;; (require 'document)
638;; (document-insert-texinfo tag (semantic-tag-buffer tag))
639;; ))
640
641;; (defun semantic-texi-update-doc (&optional tag)
642;; "Update the documentation for TAG.
643;; If the current buffer is a texinfo file, then find the source doc, and
644;; update it. If the current buffer is a source file, then get the
645;; documentation for this item, find the existing doc in the associated
646;; manual, and update that."
647;; (interactive)
648;; (cond ;;((eq major-mode 'texinfo-mode)
649;; ;; (semantic-texi-update-doc-from-texi tag))
650;; (t
651;; (semantic-texi-update-doc-from-source tag))))
9573e58b
CY
652
653(defun semantic-texi-goto-source (&optional tag)
654 "Jump to the source for the definition in the texinfo file TAG.
655If TAG is nil, it is derived from the deffn under POINT."
656 (interactive)
55b522b2 657 (unless (or (featurep 'semantic/db) (semanticdb-minor-mode-p))
9573e58b
CY
658 (error "Texinfo updating only works when `semanticdb' is being used"))
659 (semantic-fetch-tags)
660 (unless tag
661 (beginning-of-line)
662 (setq tag (semantic-current-tag)))
663 (unless (semantic-tag-of-class-p tag 'def)
664 (error "Only deffns (or defun or defvar) can be updated"))
665 (let* ((name (semantic-tag-name tag))
666 (tags (semanticdb-fast-strip-find-results
667 (semanticdb-with-match-any-mode
668 (semanticdb-brute-deep-find-tags-by-name name nil 'name))
669 ))
670
671 (done nil)
672 )
673 (save-excursion
674 (while (and tags (not done))
675 (set-buffer (semantic-tag-buffer (car tags)))
676 (unless (eq major-mode 'texinfo-mode)
677 (switch-to-buffer (semantic-tag-buffer (car tags)))
678 (goto-char (semantic-tag-start (car tags)))
679 (setq done t))
680 (setq tags (cdr tags)))
681 (if (not done)
682 (error "Could not find tag for %s" (semantic-tag-name tag)))
683 )))
684
685(provide 'semantic/texi)
686
3999968a 687;; arch-tag: a8649049-46da-407b-a620-d175c1fedca6
55b522b2 688;;; semantic/texi.el ends here