Skip to content

Instantly share code, notes, and snippets.

@stew
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save stew/9374875 to your computer and use it in GitHub Desktop.

Select an option

Save stew/9374875 to your computer and use it in GitHub Desktop.
* tags
** load-tags-for-this-project
#+begin_src emacs-lisp
(defun find-file-upwards (file-to-find)
"Recursively searches each parent directory starting from the default-directory.
looking for a file with name file-to-find. Returns the path to it
or nil if not found."
(labels
((find-file-r (path)
(let* ((parent (file-name-directory path))
(possible-file (concat parent file-to-find)))
(cond
((file-exists-p possible-file) possible-file) ; Found
;; The parent of ~ is nil and the parent of / is itself.
;; Thus the terminating condition for not finding the file
;; accounts for both.
((or (null parent) (equal parent (directory-file-name parent))) nil) ; Not found
(t (find-file-r (directory-file-name parent))))))) ; Continue
(find-file-r default-directory)))
(defun load-tags-for-this-project ()
(interactive)
(let ((my-tags-file (find-file-upwards "TAGS")))
(when my-tags-file
(message "Loading tags file: %s" my-tags-file)
(visit-tags-table my-tags-file))))
#+end_src
** find-next-tag
#+begin_src emacs-lisp
(defun find-next-tag ()
(interactive)
(find-tag "" t))
#+end_src
** list-tags-for-this-file
#+begin_src emacs-lisp
(defun list-tags-for-this-file ()
(interactive)
(list-tags buffer-file-name))
#+end_src
** keybindings
#+begin_src emacs-lisp
(global-set-key (kbd "C-M-t") 'find-tag)
(global-set-key (kbd "C-M-,") 'pop-tag-mark)
(global-set-key (kbd "C-M-.") 'find-next-tag)
(global-set-key (kbd "M-?") 'complete-tag)
(global-set-key (kbd "s-t") 'list-tags-for-this-file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment