Mercurial > emacs
annotate lisp/org/org-ctags.el @ 109313:e856a274549b
Constify functions taking char *
* alloc.c (pending_malloc_warning, malloc_warning): Add const.
* callproc.c (relocate_fd, getenv_internal_1, getenv_internal)
(egetenv): Likewise.
* doprnt.c (doprnt): Likewise.
* editfns.c (set_time_zone_rule, format2): Likewise.
* emacs.c (decode_env_path): Likewise.
* eval.c (signal_error, error): Likewise.
* insdel.c (replace_range_2): Likewise.
* keyboard.c (cmd_error_internal): Likewise.
* lread.c (isfloat_string, make_symbol, dir_warning): Likewise.
* print.c (write_string, write_string_1, print_error_message):
Likewise.
* vm-limit.c (warn_function, memory_warnings): Likewise.
* xdisp.c (message1, message1_nolog, message_with_string)
(vmessage, message, message_nolog): Likewise.
* emacs.c: Remove duplicate declaration.
* keyboard.h: Likewise.
* lisp.h: Update prototypes.
author | Andreas Schwab <schwab@linux-m68k.org> |
---|---|
date | Sun, 11 Jul 2010 11:27:13 +0200 |
parents | b781593bacdc |
children | a150e8a14679 |
rev | line source |
---|---|
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
1 ;;; org-ctags.el - Integrate Emacs "tags" facility with org mode. |
108180
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
2 ;; |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
3 ;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
4 |
108180
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
5 ;; Author: Paul Sexton <eeeickythump@gmail.com> |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
6 ;; Version: 1.0 |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
7 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
8 ;; Keywords: org, wp |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
9 ;; Version: 6.35i |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
10 ;; |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
11 ;; This file is part of GNU Emacs. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
12 ;; |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
14 ;; it under the terms of the GNU General Public License as published by |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
16 ;; (at your option) any later version. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
17 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
18 ;; GNU Emacs is distributed in the hope that it will be useful, |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
21 ;; GNU General Public License for more details. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
22 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
23 ;; You should have received a copy of the GNU General Public License |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
25 |
108180
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
26 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
27 ;; Synopsis |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
28 ;; ======== |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
29 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
30 ;; Allows org-mode to make use of the Emacs `etags' system. Defines tag |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
31 ;; destinations in org-mode files as any text between <<double angled |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
32 ;; brackets>>. This allows the tags-generation program `exuberant ctags' to |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
33 ;; parse these files and create tag tables that record where these |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
34 ;; destinations are found. Plain [[links]] in org mode files which do not have |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
35 ;; <<matching destinations>> within the same file will then be interpreted as |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
36 ;; links to these 'tagged' destinations, allowing seamless navigation between |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
37 ;; multiple org-mode files. Topics can be created in any org mode file and |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
38 ;; will always be found by plain links from other files. Other file types |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
39 ;; recognised by ctags (source code files, latex files, etc) will also be |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
40 ;; available as destinations for plain links, and similarly, org-mode links |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
41 ;; will be available as tags from source files. Finally, the function |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
42 ;; `org-ctags-find-tag-interactive' lets you choose any known tag, using |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
43 ;; autocompletion, and quickly jump to it. |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
44 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
45 ;; Installation |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
46 ;; ============ |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
47 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
48 ;; Install org mode |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
49 ;; Ensure org-ctags.el is somewhere in your emacs load path. |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
50 ;; Download and install Exuberant ctags -- "http://ctags.sourceforge.net/" |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
51 ;; Edit your .emacs file (see next section) and load emacs. |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
52 |
108180
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
53 ;; To put in your init file (.emacs): |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
54 ;; ================================== |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
55 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
56 ;; Assuming you already have org mode installed and set up: |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
57 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
58 ;; (setq org-ctags-path-to-ctags "/path/to/ctags/executable") |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
59 ;; (add-hook 'org-mode-hook |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
60 ;; (lambda () |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
61 ;; (define-key org-mode-map "\C-co" 'org-ctags-find-tag-interactive))) |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
62 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
63 ;; By default, with org-ctags loaded, org will first try and visit the tag |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
64 ;; with the same name as the link; then, if unsuccessful, ask the user if |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
65 ;; he/she wants to rebuild the 'TAGS' database and try again; then ask if |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
66 ;; the user wishes to append 'tag' as a new toplevel heading at the end of |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
67 ;; the buffer; and finally, defer to org's default behaviour which is to |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
68 ;; search the entire text of the current buffer for 'tag'. |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
69 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
70 ;; This behaviour can be modified by changing the value of |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
71 ;; ORG-CTAGS-OPEN-LINK-FUNCTIONS. For example I have the following in my |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
72 ;; .emacs, which describes the same behaviour as the above paragraph with |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
73 ;; one difference: |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
74 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
75 ;; (setq org-ctags-open-link-functions |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
76 ;; '(org-ctags-find-tag |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
77 ;; org-ctags-ask-rebuild-tags-file-then-find-tag |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
78 ;; org-ctags-ask-append-topic |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
79 ;; org-ctags-fail-silently)) ; <-- prevents org default behaviour |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
80 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
81 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
82 ;; Usage |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
83 ;; ===== |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
84 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
85 ;; When you click on a link "[[foo]]" and org cannot find a matching "<<foo>>" |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
86 ;; in the current buffer, the tags facility will take over. The file TAGS in |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
87 ;; the active directory is examined to see if the tags facility knows about |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
88 ;; "<<foo>>" in any other files. If it does, the matching file will be opened |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
89 ;; and the cursor will jump to the position of "<<foo>>" in that file. |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
90 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
91 ;; User-visible functions: |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
92 ;; - `org-ctags-find-tag-interactive': type a tag (plain link) name and visit |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
93 ;; it. With autocompletion. Bound to ctrl-O in the above setup. |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
94 ;; - All the etags functions should work. These include: |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
95 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
96 ;; M-. `find-tag' -- finds the tag at point |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
97 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
98 ;; C-M-. find-tag based on regular expression |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
99 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
100 ;; M-x tags-search RET -- like C-M-. but searches through ENTIRE TEXT |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
101 ;; of ALL the files referenced in the TAGS file. A quick way to |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
102 ;; search through an entire 'project'. |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
103 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
104 ;; M-* "go back" from a tag jump. Like `org-mark-ring-goto'. |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
105 ;; You may need to bind this key yourself with (eg) |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
106 ;; (global-set-key (kbd "<M-kp-multiply>") 'pop-tag-mark) |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
107 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
108 ;; (see etags chapter in Emacs manual for more) |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
109 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
110 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
111 ;; Keeping the TAGS file up to date |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
112 ;; ================================ |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
113 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
114 ;; Tags mode has no way of knowing that you have created new tags by typing in |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
115 ;; your org-mode buffer. New tags make it into the TAGS file in 3 ways: |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
116 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
117 ;; 1. You re-run (org-ctags-create-tags "directory") to rebuild the file. |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
118 ;; 2. You put the function `org-ctags-ask-rebuild-tags-file-then-find-tag' in |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
119 ;; your `org-open-link-functions' list, as is done in the setup |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
120 ;; above. This will cause the TAGS file to be rebuilt whenever a link |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
121 ;; cannot be found. This may be slow with large file collections however. |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
122 ;; 3. You run the following from the command line (all 1 line): |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
123 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
124 ;; ctags --langdef=orgmode --langmap=orgmode:.org |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
125 ;; --regex-orgmode="/<<([^>]+)>>/\1/d,definition/" |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
126 ;; -f /your/path/TAGS -e -R /your/path/*.org |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
127 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
128 ;; If you are paranoid, you might want to run (org-ctags-create-tags |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
129 ;; "/path/to/org/files") at startup, by including the following toplevel form |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
130 ;; in .emacs. However this can cause a pause of several seconds if ctags has |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
131 ;; to scan lots of files. |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
132 ;; |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
133 ;; (progn |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
134 ;; (message "-- rebuilding tags tables...") |
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
135 ;; (mapc 'org-create-tags tags-table-list)) |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
136 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
137 (eval-when-compile (require 'cl)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
138 (require 'org) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
139 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
140 (defgroup org-ctags nil |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
141 "Options concerning use of ctags within org mode." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
142 :tag "Org-Ctags" |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
143 :group 'org-link) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
144 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
145 (defvar org-ctags-enabled-p t |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
146 "Activate ctags support in org mode?") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
147 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
148 (defvar org-ctags-tag-regexp "/<<([^>]+)>>/\\1/d,definition/" |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
149 "Regexp expression used by ctags external program, that matches |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
150 tag destinations in org-mode files. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
151 Format is: /REGEXP/TAGNAME/FLAGS,TAGTYPE/ |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
152 See the ctags documentation for more information.") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
153 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
154 (defcustom org-ctags-path-to-ctags |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
155 (case system-type |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
156 (windows-nt "ctags.exe") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
157 (darwin "ctags-exuberant") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
158 (t "ctags-exuberant")) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
159 "Full path to the ctags executable file." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
160 :group 'org-ctags |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
161 :type 'file) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
162 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
163 (defcustom org-ctags-open-link-functions |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
164 '(org-ctags-find-tag |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
165 org-ctags-ask-rebuild-tags-file-then-find-tag |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
166 org-ctags-ask-append-topic) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
167 "List of functions to be prepended to ORG-OPEN-LINK-FUNCTIONS when |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
168 ORG-CTAGS is active." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
169 :group 'org-ctags |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
170 :type 'hook |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
171 :options '(org-ctags-find-tag |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
172 org-ctags-ask-rebuild-tags-file-then-find-tag |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
173 org-ctags-rebuild-tags-file-then-find-tag |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
174 org-ctags-ask-append-topic |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
175 org-ctags-append-topic |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
176 org-ctags-ask-visit-buffer-or-file |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
177 org-ctags-visit-buffer-or-file |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
178 org-ctags-fail-silently)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
179 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
180 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
181 (defvar org-ctags-tag-list nil |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
182 "List of all tags in the active TAGS file. Created as a local |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
183 variable in each buffer.") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
184 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
185 (defcustom org-ctags-new-topic-template |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
186 "* <<%t>>\n\n\n\n\n\n" |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
187 "Text to insert when creating a new org file via opening a hyperlink. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
188 The following patterns are replaced in the string: |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
189 `%t' - replaced with the capitalized title of the hyperlink" |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
190 :group 'org-ctags |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
191 :type 'string) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
192 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
193 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
194 (add-hook 'org-mode-hook |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
195 (lambda () |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
196 (when (and org-ctags-enabled-p |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
197 (buffer-file-name)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
198 ;; Make sure this file's directory is added to default |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
199 ;; directories in which to search for tags. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
200 (let ((tags-filename |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
201 (expand-file-name |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
202 (concat (file-name-directory (buffer-file-name)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
203 "/TAGS")))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
204 (when (file-exists-p tags-filename) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
205 (visit-tags-table tags-filename)))))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
206 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
207 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
208 (defadvice visit-tags-table (after org-ctags-load-tag-list activate compile) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
209 (when (and org-ctags-enabled-p tags-file-name) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
210 (set (make-local-variable 'org-ctags-tag-list) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
211 (org-ctags-all-tags-in-current-tags-table)))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
212 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
213 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
214 (defun org-ctags-enable () |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
215 (put 'org-mode 'find-tag-default-function 'org-ctags-find-tag-at-point) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
216 (setq org-ctags-enabled-p t) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
217 (dolist (fn org-ctags-open-link-functions) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
218 (add-hook 'org-open-link-functions fn t))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
219 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
220 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
221 ;;; General utility functions. =============================================== |
108180
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
222 ;; These work outside org-ctags mode. |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
223 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
224 (defun org-ctags-get-filename-for-tag (tag) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
225 "TAG is a string. Search the active TAGS file for a matching tag, |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
226 and if found, return a list containing the filename, line number, and |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
227 buffer position where the tag is found." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
228 (interactive "sTag: ") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
229 (unless tags-file-name |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
230 (call-interactively (visit-tags-table))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
231 (save-excursion |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
232 (visit-tags-table-buffer 'same) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
233 (when tags-file-name |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
234 (with-current-buffer (get-file-buffer tags-file-name) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
235 (goto-char (point-min)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
236 (cond |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
237 ((re-search-forward (format "^.*%s\\([0-9]+\\),\\([0-9]+\\)$" |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
238 (regexp-quote tag)) nil t) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
239 (let ((line (string-to-number (match-string 1))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
240 (pos (string-to-number (match-string 2)))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
241 (cond |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
242 ((re-search-backward "\n\\(.*\\),[0-9]+\n") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
243 (list (match-string 1) line pos)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
244 (t ; can't find a file name preceding the matched |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
245 ; tag?? |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
246 (error "Malformed TAGS file: %s" (buffer-name)))))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
247 (t ; tag not found |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
248 nil)))))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
249 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
250 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
251 (defun org-ctags-all-tags-in-current-tags-table () |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
252 "Read all tags defined in the active TAGS file, into a list of strings. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
253 Return the list." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
254 (interactive) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
255 (let ((taglist nil)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
256 (unless tags-file-name |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
257 (call-interactively (visit-tags-table))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
258 (save-excursion |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
259 (visit-tags-table-buffer 'same) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
260 (with-current-buffer (get-file-buffer tags-file-name) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
261 (goto-char (point-min)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
262 (while (re-search-forward "^.*\\(.*\\)\\([0-9]+\\),\\([0-9]+\\)$" |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
263 nil t) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
264 (push (substring-no-properties (match-string 1)) taglist))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
265 taglist))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
266 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
267 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
268 (defun org-ctags-string-search-and-replace (search replace string) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
269 "Replace all instances of SEARCH with REPLACE in STRING." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
270 (replace-regexp-in-string (regexp-quote search) replace string t t)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
271 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
272 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
273 (defun y-or-n-minibuffer (prompt) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
274 (let ((use-dialog-box nil)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
275 (y-or-n-p prompt))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
276 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
277 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
278 ;;; Internal functions ======================================================= |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
279 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
280 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
281 (defun org-ctags-open-file (name &optional title) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
282 "Visit or create a file called `NAME.org', and insert a new topic titled |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
283 NAME (or TITLE if supplied)." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
284 (interactive "sFile name: ") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
285 (let ((filename (substitute-in-file-name (expand-file-name name)))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
286 (condition-case v |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
287 (progn |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
288 (org-open-file name t) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
289 (message "Opened file OK") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
290 (goto-char (point-max)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
291 (insert (org-ctags-string-search-and-replace |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
292 "%t" (capitalize (or title name)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
293 org-ctags-new-topic-template)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
294 (message "Inserted new file text OK") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
295 (org-mode-restart)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
296 (error (error "Error %S in org-ctags-open-file" v))))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
297 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
298 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
299 ;;;; Misc interoperability with etags system ================================= |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
300 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
301 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
302 (defadvice find-tag (before org-ctags-set-org-mark-before-finding-tag |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
303 activate compile) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
304 "Before trying to find a tag, save our current position on org mark ring." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
305 (save-excursion |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
306 (if (and (org-mode-p) org-ctags-enabled-p) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
307 (org-mark-ring-push)))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
308 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
309 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
310 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
311 (defun org-ctags-find-tag-at-point () |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
312 "Determine default tag to search for, based on text at point. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
313 If there is no plausible default, return nil." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
314 (let (from to bound) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
315 (when (or (ignore-errors |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
316 ;; Look for hyperlink around `point'. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
317 (save-excursion |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
318 (search-backward "[[") (setq from (+ 2 (point)))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
319 (save-excursion |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
320 (goto-char from) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
321 (search-forward "]") (setq to (- (point) 1))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
322 (and (> to from) (>= (point) from) (<= (point) to))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
323 (progn |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
324 ;; Look at text around `point'. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
325 (save-excursion |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
326 (skip-syntax-backward "w_") (setq from (point))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
327 (save-excursion |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
328 (skip-syntax-forward "w_") (setq to (point))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
329 (> to from)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
330 ;; Look between `line-beginning-position' and `point'. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
331 (save-excursion |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
332 (and (setq bound (line-beginning-position)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
333 (skip-syntax-backward "^w_" bound) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
334 (> (setq to (point)) bound) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
335 (skip-syntax-backward "w_") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
336 (setq from (point)))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
337 ;; Look between `point' and `line-end-position'. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
338 (save-excursion |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
339 (and (setq bound (line-end-position)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
340 (skip-syntax-forward "^w_" bound) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
341 (< (setq from (point)) bound) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
342 (skip-syntax-forward "w_") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
343 (setq to (point))))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
344 (buffer-substring-no-properties from to)))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
345 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
346 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
347 ;;; Functions for use with 'org-open-link-functions' hook ================= |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
348 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
349 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
350 (defun org-ctags-find-tag (name) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
351 "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
352 Look for a tag called `NAME' in the current TAGS table. If it is found, |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
353 visit the file and location where the tag is found." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
354 (interactive "sTag: ") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
355 (let ((old-buf (current-buffer)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
356 (old-pnt (point-marker)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
357 (old-mark (copy-marker (mark-marker)))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
358 (condition-case nil |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
359 (progn (find-tag name) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
360 t) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
361 (error |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
362 ;; only restore old location if find-tag raises error |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
363 (set-buffer old-buf) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
364 (goto-char old-pnt) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
365 (set-marker (mark-marker) old-mark) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
366 nil)))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
367 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
368 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
369 (defun org-ctags-visit-buffer-or-file (name &optional create) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
370 "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
371 Visit buffer named `NAME.org'. If there is no such buffer, visit the file |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
372 with the same name if it exists. If the file does not exist, then behaviour |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
373 depends on the value of CREATE. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
374 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
375 If CREATE is nil (default), then return nil. Do not create a new file. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
376 If CREATE is t, create the new file and visit it. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
377 If CREATE is the symbol `ask', then ask the user if they wish to create |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
378 the new file." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
379 (interactive) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
380 (let ((filename (concat (substitute-in-file-name |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
381 (expand-file-name name)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
382 ".org"))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
383 (cond |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
384 ((get-buffer (concat name ".org")) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
385 ;; Buffer is already open |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
386 (switch-to-buffer (get-buffer (concat name ".org")))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
387 ((file-exists-p filename) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
388 ;; File exists but is not open --> open it |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
389 (message "Opening existing org file `%S'..." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
390 filename) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
391 (org-open-file filename t)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
392 ((or (eql create t) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
393 (and (eql create 'ask) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
394 (y-or-n-p (format "File `%s.org' not found; create?" name)))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
395 (org-ctags-open-file filename name)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
396 (t ;; File does not exist, and we don't want to create it. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
397 nil)))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
398 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
399 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
400 (defun org-ctags-ask-visit-buffer-or-file (name) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
401 "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
402 Wrapper for org-ctags-visit-buffer-or-file, which ensures the user is |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
403 asked before creating a new file." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
404 (org-ctags-visit-buffer-or-file name 'ask)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
405 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
406 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
407 (defun org-ctags-append-topic (name &optional narrowp) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
408 "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
409 Append a new toplevel heading to the end of the current buffer. The |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
410 heading contains NAME surrounded by <<angular brackets>>, thus making |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
411 the heading a destination for the tag `NAME'." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
412 (interactive "sTopic: ") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
413 (widen) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
414 (goto-char (point-max)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
415 (newline 2) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
416 (message "Adding topic in buffer %s" (buffer-name)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
417 (insert (org-ctags-string-search-and-replace |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
418 "%t" (capitalize name) org-ctags-new-topic-template)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
419 (backward-char 4) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
420 (org-update-radio-target-regexp) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
421 (end-of-line) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
422 (forward-line 2) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
423 (when narrowp |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
424 ;;(org-tree-to-indirect-buffer 1) ;; opens new frame |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
425 (org-narrow-to-subtree)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
426 t) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
427 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
428 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
429 (defun org-ctags-ask-append-topic (name &optional narrowp) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
430 "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
431 Wrapper for org-ctags-append-topic, which first asks the user if they want |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
432 to append a new topic." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
433 (if (y-or-n-p (format "Topic `%s' not found; append to end of buffer?" |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
434 name)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
435 (org-ctags-append-topic name narrowp) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
436 nil)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
437 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
438 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
439 (defun org-ctags-rebuild-tags-file-then-find-tag (name) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
440 "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
441 Like ORG-CTAGS-FIND-TAG, but calls the external ctags program first, |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
442 to rebuild (update) the TAGS file." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
443 (unless tags-file-name |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
444 (call-interactively (visit-tags-table))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
445 (when (buffer-file-name) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
446 (org-ctags-create-tags)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
447 (org-ctags-find-tag name)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
448 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
449 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
450 (defun org-ctags-ask-rebuild-tags-file-then-find-tag (name) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
451 "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
452 Wrapper for org-ctags-rebuild-tags-file-then-find-tag." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
453 (if (and (buffer-file-name) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
454 (y-or-n-p |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
455 (format |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
456 "Tag `%s' not found. Rebuild table `%s/TAGS' and look again?" |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
457 name |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
458 (file-name-directory (buffer-file-name))))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
459 (org-ctags-rebuild-tags-file-then-find-tag name) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
460 nil)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
461 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
462 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
463 (defun org-ctags-fail-silently (name) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
464 "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
465 Put as the last function in the list if you want to prevent org's default |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
466 behaviour of free text search." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
467 t) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
468 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
469 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
470 ;;; User-visible functions =================================================== |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
471 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
472 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
473 (defun org-ctags-create-tags (&optional directory-name) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
474 "(Re)create tags file in the directory of the active buffer, |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
475 containing tag definitions for all the files in the directory and its |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
476 subdirectories which are recognised by ctags. This will include |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
477 files ending in `.org' as well as most other source files (.C, |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
478 .H, .EL, .LISP, etc). All the resulting tags end up in one file, |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
479 called TAGS, located in the directory. This function |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
480 may take several seconds to finish if the directory or its |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
481 subdirectories contain large numbers of taggable files." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
482 (interactive) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
483 (assert (buffer-file-name)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
484 (let ((dir-name (or directory-name |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
485 (file-name-directory (buffer-file-name)))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
486 (exitcode nil)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
487 (save-excursion |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
488 (setq exitcode |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
489 (shell-command |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
490 (format (concat "%s --langdef=orgmode --langmap=orgmode:.org " |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
491 "--regex-orgmode=\"%s\" -f \"%s\" -e -R \"%s\"") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
492 org-ctags-path-to-ctags |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
493 org-ctags-tag-regexp |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
494 (expand-file-name (concat dir-name "/TAGS")) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
495 (expand-file-name (concat dir-name "/*"))))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
496 (cond |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
497 ((eql 0 exitcode) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
498 (set (make-local-variable 'org-ctags-tag-list) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
499 (org-ctags-all-tags-in-current-tags-table))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
500 (t |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
501 ;; This seems to behave differently on Linux, so just ignore |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
502 ;; error codes for now |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
503 ;;(error "Calling ctags executable resulted in error code: %s" |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
504 ;; exitcode) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
505 nil))))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
506 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
507 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
508 (defvar org-ctags-find-tag-history nil |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
509 "History of tags visited by org-ctags-find-tag-interactive.") |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
510 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
511 (defun org-ctags-find-tag-interactive () |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
512 "Prompt for the name of a tag, with autocompletion, then visit |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
513 the named tag. Uses ido-mode if available. |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
514 If the user enters a string that does not match an existing tag, create |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
515 a new topic." |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
516 (interactive) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
517 (let* ((completing-read-fn (if (fboundp 'ido-completing-read) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
518 'ido-completing-read |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
519 'completing-read)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
520 (tag (funcall completing-read-fn "Topic: " org-ctags-tag-list |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
521 nil 'confirm nil 'org-ctags-find-tag-history))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
522 (when tag |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
523 (cond |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
524 ((member tag org-ctags-tag-list) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
525 ;; Existing tag |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
526 (push tag org-ctags-find-tag-history) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
527 (find-tag tag)) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
528 (t |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
529 ;; New tag |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
530 (run-hook-with-args-until-success |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
531 'org-open-link-functions tag)))))) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
532 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
533 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
534 (org-ctags-enable) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
535 |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
536 (provide 'org-ctags) |
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
537 |
108180
b781593bacdc
Fix commenting convention
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
107863
diff
changeset
|
538 ;; arch-tag: 4b1ddd5a-8529-4b17-bcde-96a922d26343 |
107863
594e81986a75
2010-04-10 Carsten Dominik <carsten.dominik@gmail.com>
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff
changeset
|
539 ;;; org-ctags.el ends here |