;;; org-ctags.el - Integrate Emacs "tags" facility with org mode.
;;
-;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 2007-2012 Free Software Foundation, Inc.
;; Author: Paul Sexton <eeeickythump@gmail.com>
-;; Version: 1.0
+
;; Keywords: org, wp
-;; Version: 6.35i
;;
;; This file is part of GNU Emacs.
;;
;; links to these 'tagged' destinations, allowing seamless navigation between
;; multiple org-mode files. Topics can be created in any org mode file and
;; will always be found by plain links from other files. Other file types
-;; recognised by ctags (source code files, latex files, etc) will also be
+;; recognized by ctags (source code files, latex files, etc) will also be
;; available as destinations for plain links, and similarly, org-mode links
;; will be available as tags from source files. Finally, the function
;; `org-ctags-find-tag-interactive' lets you choose any known tag, using
;; (message "-- rebuilding tags tables...")
;; (mapc 'org-create-tags tags-table-list))
+;;; Code:
+
(eval-when-compile (require 'cl))
+
(require 'org)
+(declare-function org-pop-to-buffer-same-window "org-compat" (&optional buffer-or-name norecord label))
+
(defgroup org-ctags nil
"Options concerning use of ctags within org mode."
:tag "Org-Ctags"
"Activate ctags support in org mode?")
(defvar org-ctags-tag-regexp "/<<([^>]+)>>/\\1/d,definition/"
- "Regexp expression used by ctags external program, that matches
-tag destinations in org-mode files.
+ "Regexp expression used by ctags external program.
+The regexp matches tag destinations in org-mode files.
Format is: /REGEXP/TAGNAME/FLAGS,TAGTYPE/
See the ctags documentation for more information.")
'(org-ctags-find-tag
org-ctags-ask-rebuild-tags-file-then-find-tag
org-ctags-ask-append-topic)
- "List of functions to be prepended to ORG-OPEN-LINK-FUNCTIONS when
-ORG-CTAGS is active."
+ "List of functions to be prepended to ORG-OPEN-LINK-FUNCTIONS when ORG-CTAGS is active."
:group 'org-ctags
:type 'hook
:options '(org-ctags-find-tag
(defvar org-ctags-tag-list nil
- "List of all tags in the active TAGS file. Created as a local
-variable in each buffer.")
+ "List of all tags in the active TAGS file.
+Created as a local variable in each buffer.")
(defcustom org-ctags-new-topic-template
"* <<%t>>\n\n\n\n\n\n"
(add-hook 'org-open-link-functions fn t)))
-;;; General utility functions. ===============================================
+;;; General utility functions. ===============================================
;; These work outside org-ctags mode.
(defun org-ctags-get-filename-for-tag (tag)
- "TAG is a string. Search the active TAGS file for a matching tag,
-and if found, return a list containing the filename, line number, and
+ "TAG is a string. Search the active TAGS file for a matching tag.
+If the tag is found, return a list containing the filename, line number, and
buffer position where the tag is found."
(interactive "sTag: ")
(unless tags-file-name
(defun org-ctags-open-file (name &optional title)
- "Visit or create a file called `NAME.org', and insert a new topic titled
-NAME (or TITLE if supplied)."
+ "Visit or create a file called `NAME.org', and insert a new topic.
+The new topic will be titled NAME (or TITLE if supplied)."
(interactive "sFile name: ")
(let ((filename (substitute-in-file-name (expand-file-name name))))
(condition-case v
activate compile)
"Before trying to find a tag, save our current position on org mark ring."
(save-excursion
- (if (and (org-mode-p) org-ctags-enabled-p)
+ (if (and (eq major-mode 'org-mode) org-ctags-enabled-p)
(org-mark-ring-push))))
(defun org-ctags-find-tag (name)
"This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS.
-Look for a tag called `NAME' in the current TAGS table. If it is found,
+Look for a tag called `NAME' in the current TAGS table. If it is found,
visit the file and location where the tag is found."
(interactive "sTag: ")
(let ((old-buf (current-buffer))
(defun org-ctags-visit-buffer-or-file (name &optional create)
"This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS.
-Visit buffer named `NAME.org'. If there is no such buffer, visit the file
-with the same name if it exists. If the file does not exist, then behaviour
+Visit buffer named `NAME.org'. If there is no such buffer, visit the file
+with the same name if it exists. If the file does not exist, then behavior
depends on the value of CREATE.
-If CREATE is nil (default), then return nil. Do not create a new file.
+If CREATE is nil (default), then return nil. Do not create a new file.
If CREATE is t, create the new file and visit it.
If CREATE is the symbol `ask', then ask the user if they wish to create
the new file."
(cond
((get-buffer (concat name ".org"))
;; Buffer is already open
- (switch-to-buffer (get-buffer (concat name ".org"))))
+ (org-pop-to-buffer-same-window (get-buffer (concat name ".org"))))
((file-exists-p filename)
;; File exists but is not open --> open it
(message "Opening existing org file `%S'..."
(if (and (buffer-file-name)
(y-or-n-p
(format
- "Tag `%s' not found. Rebuild table `%s/TAGS' and look again?"
+ "Tag `%s' not found. Rebuild table `%s/TAGS' and look again?"
name
(file-name-directory (buffer-file-name)))))
(org-ctags-rebuild-tags-file-then-find-tag name)
(defun org-ctags-fail-silently (name)
"This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS.
Put as the last function in the list if you want to prevent org's default
-behaviour of free text search."
+behavior of free text search."
t)
(defun org-ctags-create-tags (&optional directory-name)
- "(Re)create tags file in the directory of the active buffer,
-containing tag definitions for all the files in the directory and its
-subdirectories which are recognised by ctags. This will include
-files ending in `.org' as well as most other source files (.C,
-.H, .EL, .LISP, etc). All the resulting tags end up in one file,
-called TAGS, located in the directory. This function
-may take several seconds to finish if the directory or its
-subdirectories contain large numbers of taggable files."
+ "(Re)create tags file in the directory of the active buffer.
+The file will contain tag definitions for all the files in the
+directory and its subdirectories which are recognized by ctags.
+This will include files ending in `.org' as well as most other
+source files (.C, .H, .EL, .LISP, etc). All the resulting tags
+end up in one file, called TAGS, located in the directory. This
+function may take several seconds to finish if the directory or
+its subdirectories contain large numbers of taggable files."
(interactive)
(assert (buffer-file-name))
(let ((dir-name (or directory-name
"History of tags visited by org-ctags-find-tag-interactive.")
(defun org-ctags-find-tag-interactive ()
- "Prompt for the name of a tag, with autocompletion, then visit
-the named tag. Uses ido-mode if available.
+ "Prompt for the name of a tag, with autocompletion, then visit the named tag.
+Uses `ido-mode' if available.
If the user enters a string that does not match an existing tag, create
a new topic."
(interactive)
(provide 'org-ctags)
-;; arch-tag: 4b1ddd5a-8529-4b17-bcde-96a922d26343
;;; org-ctags.el ends here