Guest User

Untitled

a guest
Apr 25th, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. ;;; etags-kill.el --- kill useless buffers when browsing tags
  2.  
  3. ;; Copyright (C) 2009 Free Software Foundation, Inc.
  4.  
  5. ;; Author: Yann Hodique <yhodique@vmware.com>
  6. ;; Keywords:
  7.  
  8. ;; This file is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 2, or (at your option)
  11. ;; any later version.
  12.  
  13. ;; This file is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17.  
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to
  20. ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. ;; Boston, MA 02111-1307, USA.
  22.  
  23. ;;; Commentary:
  24.  
  25. ;; This code will kill buffers that:
  26. ;; - have been opened by `find-tag' (was not open before)
  27. ;; - are not living anymore in the tag stack (you just M-* from it)
  28.  
  29. ;; An exception is if user uses C-u M-* instead. In this case they will be
  30. ;; considered as already open for any future `pop-tag-mark'
  31.  
  32. ;; Limitation: this will work only if `pop-tag-mark' is run from the
  33. ;; buffer. This is how I browse, so I don't see it as a major limitation.
  34.  
  35. ;;; Code:
  36.  
  37. (defvar yh/destroy-buffer-when-pop nil)
  38. (make-variable-buffer-local 'yh/destroy-buffer-when-pop)
  39.  
  40. (defvar yh/orig-find-file-noselect (symbol-function 'find-file-noselect))
  41.  
  42. (defun yh/find-file-noselect-and-record (file &optional nowarn rawfile wildcards)
  43. (let ((buffer (funcall yh/orig-find-file-noselect file nowarn rawfile wildcards)))
  44. (with-current-buffer buffer
  45. (setq yh/destroy-buffer-when-pop t))
  46. buffer))
  47.  
  48. (defadvice tag-find-file-of-tag-noselect (around yh/tag-ff-around (file) act)
  49. (flet ((find-file-noselect (file &optional nowarn rawfile wildcards)
  50. (yh/find-file-noselect-and-record file nowarn rawfile wildcards)))
  51. ad-do-it))
  52.  
  53. (defadvice pop-tag-mark (around yh/tag-pop-around () act)
  54. (let* ((yh/buffer (current-buffer))
  55. (yh/pop-destroy-buffer (buffer-local-value 'yh/destroy-buffer-when-pop yh/buffer)))
  56. (when current-prefix-arg
  57. (setq yh/pop-destroy-buffer nil)
  58. (with-current-buffer yh/buffer
  59. (setq yh/destroy-buffer-when-pop nil)))
  60. ad-do-it
  61. (if (and yh/pop-destroy-buffer (not (eq yh/buffer (current-buffer))))
  62. (kill-buffer yh/buffer))))
  63.  
  64. ;; need for an advice here since it can be called from `tag-find-file-of-tag-noselect'
  65. (defadvice visit-tags-table-buffer (around yh/visit-tags-around (&optional cont) act)
  66. (flet ((find-file-noselect (file &optional nowarn rawfile wildcards)
  67. (funcall yh/orig-find-file-noselect file nowarn rawfile wildcards)))
  68. ad-do-it))
  69.  
  70. (provide 'etags-kill)
  71. ;;; etags-kill.el ends here
Add Comment
Please, Sign In to add comment