From 05d2d1855cddc8d5c310d718c07d91ae861b8436 Mon Sep 17 00:00:00 2001 From: Bob Rogers Date: Wed, 23 Feb 2022 16:23:17 -0500 Subject: [PATCH] Make Buffer-menu-visit-tags-table more circumspect * lisp/buff-menu.el: + (Buffer-menu-visit-tags-table): Ask before visit-tags-table on a buffer not already in tags-table-mode, lest it destroy state. --- lisp/buff-menu.el | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el index 50c2c155ca..0bed539008 100644 --- a/lisp/buff-menu.el +++ b/lisp/buff-menu.el @@ -530,10 +530,21 @@ Buffer-menu-multi-occur (defun Buffer-menu-visit-tags-table () "Visit the tags table in the buffer on this line. See `visit-tags-table'." (interactive nil Buffer-menu-mode) - (let ((file (buffer-file-name (Buffer-menu-buffer t)))) - (if file - (visit-tags-table file) - (error "Specified buffer has no file")))) + (let* ((buffer (Buffer-menu-buffer t)) + (file (buffer-file-name buffer))) + (or file + (error "Specified buffer has no file")) + ;; Ensure that it's really a tags file buffer (or the user at + ;; least believes it should be). Otherwise, visit-tags-table will + ;; change the mode and discard any undo information. + (if (not (or (eq (with-current-buffer buffer + major-mode) + 'tags-table-mode) + (yes-or-no-p + (format "%s is not a tags table; visit as such anyway? " + buffer)))) + (error "Aborted.")) + (visit-tags-table file))) (defun Buffer-menu-1-window () "Select this line's buffer, alone, in full frame." -- 2.34.1