2021-03-15 00:08:34 -04:00
|
|
|
;;; semantic/mru-bookmark.el --- Automatic bookmark tracking -*- lexical-binding: t; -*-
|
2009-09-21 02:26:07 +00:00
|
|
|
|
2025-01-01 07:39:17 +00:00
|
|
|
;; Copyright (C) 2007-2025 Free Software Foundation, Inc.
|
2009-09-21 02:26:07 +00:00
|
|
|
|
2019-05-26 00:58:28 -07:00
|
|
|
;; Author: Eric M. Ludlam <zappo@gnu.org>
|
2009-09-21 02:26:07 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2009-09-21 02:26:07 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;; Using editing hooks, track the most recently visited or poked tags,
|
|
|
|
;; and keep a list of them, with the current point in from, and sorted
|
|
|
|
;; by most recently used.
|
|
|
|
;;
|
|
|
|
;; I envision this would be used in place of switch-buffers once
|
|
|
|
;; someone got the hang of it.
|
|
|
|
;;
|
|
|
|
;; I'd also like to see this used to provide some nice defaults for
|
|
|
|
;; other programs where logical destinations or targets are the tags
|
|
|
|
;; that have been recently edited.
|
|
|
|
;;
|
|
|
|
;; Quick Start:
|
|
|
|
;;
|
|
|
|
;; M-x global-semantic-mru-bookmark-mode RET
|
|
|
|
;;
|
|
|
|
;; < edit some code >
|
|
|
|
;;
|
|
|
|
;; C-x B <select a tag name> RET
|
|
|
|
;;
|
2009-09-30 07:55:35 +00:00
|
|
|
;; In the above, the history is pre-filled with the tags you recently
|
2009-09-21 02:26:07 +00:00
|
|
|
;; edited in the order you edited them.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'semantic)
|
|
|
|
(require 'eieio-base)
|
|
|
|
(require 'ring)
|
|
|
|
|
|
|
|
(declare-function data-debug-new-buffer "data-debug")
|
|
|
|
(declare-function data-debug-insert-object-slots "eieio-datadebug")
|
|
|
|
(declare-function semantic-momentary-highlight-tag "semantic/decorate")
|
2012-10-02 02:10:29 +08:00
|
|
|
(declare-function semantic-tag-similar-p "semantic/tag-ls")
|
2009-09-21 02:26:07 +00:00
|
|
|
|
|
|
|
;;; TRACKING CORE
|
|
|
|
;;
|
|
|
|
;; Data structure for tracking MRU tag locations
|
|
|
|
|
|
|
|
(defclass semantic-bookmark (eieio-named)
|
|
|
|
((tag :initarg :tag
|
|
|
|
:type semantic-tag
|
|
|
|
:documentation "The TAG this bookmark belongs to.")
|
|
|
|
(parent :type (or semantic-tag null)
|
|
|
|
:documentation "The tag that is the parent of :tag.")
|
|
|
|
(offset :type number
|
|
|
|
:documentation "The offset from `tag' start that is
|
|
|
|
somehow interesting.")
|
|
|
|
(filename :type string
|
|
|
|
:documentation "String the tag belongs to.
|
|
|
|
Set this when the tag gets unlinked from the buffer it belongs to.")
|
|
|
|
(frequency :type number
|
|
|
|
:initform 0
|
|
|
|
:documentation "Track the frequency this tag is visited.")
|
|
|
|
(reason :type symbol
|
|
|
|
:initform t
|
|
|
|
:documentation
|
|
|
|
"The reason this tag is interesting.
|
2019-11-11 10:30:13 -08:00
|
|
|
Nice values include the following:
|
2009-09-21 02:26:07 +00:00
|
|
|
edit - created because the tag text was edited.
|
|
|
|
read - created because point lingered in tag text.
|
|
|
|
jump - jumped to another tag from this tag.
|
|
|
|
mark - created a regular mark in this tag.")
|
|
|
|
)
|
|
|
|
"A single bookmark.")
|
|
|
|
|
2021-03-15 00:08:34 -04:00
|
|
|
(cl-defmethod initialize-instance :after ((sbm semantic-bookmark) &rest _fields)
|
2009-09-21 02:26:07 +00:00
|
|
|
"Initialize the bookmark SBM with details about :tag."
|
|
|
|
(condition-case nil
|
|
|
|
(save-excursion
|
|
|
|
(oset sbm filename (semantic-tag-file-name (oref sbm tag)))
|
|
|
|
(semantic-go-to-tag (oref sbm tag))
|
|
|
|
(oset sbm parent (semantic-current-tag-parent)))
|
|
|
|
(error (message "Error bookmarking tag.")))
|
|
|
|
)
|
|
|
|
|
2015-02-04 13:49:49 -05:00
|
|
|
(cl-defmethod semantic-mrub-visit ((sbm semantic-bookmark))
|
2009-09-21 02:26:07 +00:00
|
|
|
"Visit the semantic tag bookmark SBM.
|
|
|
|
Uses `semantic-go-to-tag' and highlighting."
|
|
|
|
(require 'semantic/decorate)
|
|
|
|
(with-slots (tag filename) sbm
|
|
|
|
;; Go to the tag
|
|
|
|
(when (not (semantic-tag-in-buffer-p tag))
|
|
|
|
(let ((fn (or (semantic-tag-file-name tag)
|
|
|
|
filename)))
|
|
|
|
(set-buffer (find-file-noselect fn))))
|
|
|
|
(semantic-go-to-tag (oref sbm tag) (oref sbm parent))
|
|
|
|
;; Go back to the offset.
|
|
|
|
(condition-case nil
|
|
|
|
(let ((o (oref sbm offset)))
|
|
|
|
(forward-char o))
|
|
|
|
(error nil))
|
|
|
|
;; make it visible
|
2017-10-19 02:44:46 +03:00
|
|
|
(pop-to-buffer-same-window (current-buffer))
|
2009-09-21 02:26:07 +00:00
|
|
|
(semantic-momentary-highlight-tag tag)
|
|
|
|
))
|
|
|
|
|
2015-02-04 13:49:49 -05:00
|
|
|
(cl-defmethod semantic-mrub-update ((sbm semantic-bookmark) point reason)
|
2009-09-21 02:26:07 +00:00
|
|
|
"Update the existing bookmark SBM.
|
|
|
|
POINT is some important location.
|
|
|
|
REASON is a symbol. See slot `reason' on `semantic-bookmark'."
|
|
|
|
(condition-case nil
|
|
|
|
(progn
|
|
|
|
(with-slots (tag offset frequency) sbm
|
|
|
|
(setq offset (- point (semantic-tag-start tag)))
|
|
|
|
(setq frequency (1+ frequency))
|
|
|
|
)
|
|
|
|
(oset sbm reason reason))
|
2009-09-30 07:55:35 +00:00
|
|
|
;; This can fail on XEmacs at miscellaneous times.
|
2009-09-21 02:26:07 +00:00
|
|
|
(error nil))
|
|
|
|
)
|
|
|
|
|
2015-02-04 13:49:49 -05:00
|
|
|
(cl-defmethod semantic-mrub-preflush ((sbm semantic-bookmark))
|
2009-09-21 02:26:07 +00:00
|
|
|
"Method called on a tag before the current buffer list of tags is flushed.
|
|
|
|
If there is a buffer match, unlink the tag."
|
|
|
|
(let ((tag (oref sbm tag))
|
|
|
|
(parent (when (slot-boundp sbm 'parent)
|
|
|
|
(oref sbm parent))))
|
|
|
|
(let ((b (semantic-tag-in-buffer-p tag)))
|
|
|
|
(when (and b (eq b (current-buffer)))
|
|
|
|
(semantic--tag-unlink-from-buffer tag)))
|
|
|
|
|
|
|
|
(when parent
|
|
|
|
(let ((b (semantic-tag-in-buffer-p parent)))
|
|
|
|
(when (and b (eq b (current-buffer)))
|
|
|
|
(semantic--tag-unlink-from-buffer parent))))))
|
|
|
|
|
|
|
|
(defclass semantic-bookmark-ring ()
|
|
|
|
((ring :initarg :ring
|
|
|
|
:type ring
|
|
|
|
:documentation
|
|
|
|
"List of `semantic-bookmark' objects.
|
|
|
|
This list is maintained as a list with the first item
|
|
|
|
being the current location, and the rest being a list of
|
|
|
|
items that were recently visited.")
|
|
|
|
(current-index :initform 0
|
|
|
|
:type number
|
|
|
|
:documentation
|
|
|
|
"The current index into RING for some operation.
|
|
|
|
User commands use this to move through the ring, or reset.")
|
|
|
|
)
|
|
|
|
"Track the current MRU stack of bookmarks.
|
|
|
|
We can't use the built-in ring data structure because we need
|
|
|
|
to delete some items from the ring when we don't have the data.")
|
|
|
|
|
|
|
|
(defvar semantic-mru-bookmark-ring (semantic-bookmark-ring
|
|
|
|
:ring (make-ring 20))
|
|
|
|
"The MRU bookmark ring.
|
|
|
|
This ring tracks the most recent active tags of interest.")
|
|
|
|
|
|
|
|
(defun semantic-mrub-find-nearby-tag (point)
|
|
|
|
"Find a nearby tag to be pushed for this current location.
|
|
|
|
Argument POINT is where to find the tag near."
|
|
|
|
;; I thought this was a good idea, but it is not!
|
|
|
|
;;(semantic-fetch-tags) ;; Make sure everything is up-to-date.
|
|
|
|
(let ((tag (semantic-current-tag)))
|
|
|
|
(when (or (not tag) (semantic-tag-of-class-p tag 'type))
|
|
|
|
(let ((nearby (or (semantic-find-tag-by-overlay-next point)
|
|
|
|
(semantic-find-tag-by-overlay-prev point))))
|
|
|
|
(when nearby (setq tag nearby))))
|
|
|
|
tag))
|
|
|
|
|
2015-02-04 13:49:49 -05:00
|
|
|
(cl-defmethod semantic-mrub-push ((sbr semantic-bookmark-ring) point
|
2009-09-21 02:26:07 +00:00
|
|
|
&optional reason)
|
|
|
|
"Add a bookmark to the ring SBR from POINT.
|
|
|
|
REASON is why it is being pushed. See doc for `semantic-bookmark'
|
|
|
|
for possible reasons.
|
|
|
|
The resulting bookmark is then sorted within the ring."
|
|
|
|
(let* ((ring (oref sbr ring))
|
|
|
|
(tag (semantic-mrub-find-nearby-tag (point)))
|
|
|
|
(idx 0))
|
|
|
|
(when tag
|
|
|
|
(while (and (not (ring-empty-p ring)) (< idx (ring-size ring)))
|
|
|
|
(if (semantic-tag-similar-p (oref (ring-ref ring idx) tag)
|
|
|
|
tag)
|
|
|
|
(ring-remove ring idx))
|
|
|
|
(setq idx (1+ idx)))
|
|
|
|
;; Create a new mark
|
2025-04-06 23:56:36 -04:00
|
|
|
(let ((sbm (semantic-bookmark :object-name (semantic-tag-name tag)
|
2009-09-21 02:26:07 +00:00
|
|
|
:tag tag)))
|
|
|
|
;; Take the mark, and update it for the current state.
|
|
|
|
(ring-insert ring sbm)
|
|
|
|
(semantic-mrub-update sbm point reason))
|
|
|
|
)))
|
|
|
|
|
|
|
|
(defun semantic-mrub-cache-flush-fcn ()
|
Fix minor quoting problems in doc strings
These were glitches regardless of how or whether we tackle the
problem of grave accent in doc strings.
* lisp/calc/calc-aent.el (math-restore-placeholders):
* lisp/ido.el (ido-ignore-buffers, ido-ignore-files):
* lisp/leim/quail/cyrillic.el ("bulgarian-alt-phonetic"):
* lisp/leim/quail/hebrew.el ("hebrew-new")
("hebrew-biblical-sil"):
* lisp/leim/quail/thai.el ("thai-kesmanee"):
* lisp/progmodes/idlw-shell.el (idlwave-shell-file-name-chars):
Used curved quotes to avoid ambiguities like ‘`''’ in doc strings.
* lisp/calendar/calendar.el (calendar-month-abbrev-array):
* lisp/cedet/semantic/mru-bookmark.el (semantic-mrub-cache-flush-fcn):
* lisp/cedet/semantic/symref.el (semantic-symref-tool-baseclass):
* lisp/cedet/semantic/tag.el (semantic-tag-copy)
(semantic-tag-components):
* lisp/cedet/srecode/cpp.el (srecode-semantic-handle-:cpp):
* lisp/cedet/srecode/texi.el (srecode-texi-texify-docstring):
* lisp/emacs-lisp/byte-opt.el (byte-optimize-all-constp):
* lisp/emacs-lisp/checkdoc.el (checkdoc-message-text-engine):
* lisp/emacs-lisp/generator.el (iter-next):
* lisp/gnus/gnus-art.el (gnus-treat-strip-list-identifiers)
(gnus-article-mode-syntax-table):
* lisp/net/rlogin.el (rlogin-directory-tracking-mode):
* lisp/net/soap-client.el (soap-wsdl-get):
* lisp/net/telnet.el (telnet-mode):
* lisp/org/org-compat.el (org-number-sequence):
* lisp/org/org.el (org-remove-highlights-with-change)
(org-structure-template-alist):
* lisp/org/ox-html.el (org-html-link-org-files-as-html):
* lisp/play/handwrite.el (handwrite-10pt, handwrite-11pt)
(handwrite-12pt, handwrite-13pt):
* lisp/progmodes/f90.el (f90-mode, f90-abbrev-start):
* lisp/progmodes/idlwave.el (idlwave-mode, idlwave-check-abbrev):
* lisp/progmodes/verilog-mode.el (verilog-tool)
(verilog-string-replace-matches, verilog-preprocess)
(verilog-auto-insert-lisp, verilog-auto-insert-last):
* lisp/textmodes/makeinfo.el (makeinfo-options):
* src/font.c (Ffont_spec):
Fix minor quoting problems in doc strings, e.g., missing quote,
``x'' where `x' was meant, etc.
* lisp/erc/erc-backend.el (erc-process-sentinel-2):
Fix minor quoting problem in other string.
* lisp/leim/quail/ethiopic.el ("ethiopic"):
* lisp/term/tvi970.el (tvi970-set-keypad-mode):
Omit unnecessary quotes.
* lisp/faces.el (set-face-attribute, set-face-underline)
(set-face-inverse-video, x-create-frame-with-faces):
* lisp/gnus/gnus-group.el (gnus-group-nnimap-edit-acl):
* lisp/mail/supercite.el (sc-attribs-%@-addresses)
(sc-attribs-!-addresses, sc-attribs-<>-addresses):
* lisp/net/tramp.el (tramp-methods):
* lisp/recentf.el (recentf-show-file-shortcuts-flag):
* lisp/textmodes/artist.el (artist-ellipse-right-char)
(artist-ellipse-left-char, artist-vaporize-fuzziness)
(artist-spray-chars, artist-mode, artist-replace-string)
(artist-put-pixel, artist-text-see-thru):
* lisp/vc/ediff-util.el (ediff-submit-report):
* lisp/vc/log-edit.el (log-edit-changelog-full-paragraphs):
Use double-quotes rather than TeX markup in doc strings.
* lisp/skeleton.el (skeleton-pair-insert-maybe):
Reword to avoid the need for grave accent and apostrophe.
* lisp/xt-mouse.el (xterm-mouse-tracking-enable-sequence):
Don't use grave and acute accents to quote.
2015-05-19 14:59:15 -07:00
|
|
|
"Function called in the `semantic-before-toplevel-cache-flush-hook'.
|
2009-09-21 02:26:07 +00:00
|
|
|
Cause tags in the ring to become unlinked."
|
|
|
|
(let* ((ring (oref semantic-mru-bookmark-ring ring))
|
|
|
|
(len (ring-length ring))
|
|
|
|
(idx 0)
|
|
|
|
)
|
|
|
|
(while (< idx len)
|
|
|
|
(semantic-mrub-preflush (ring-ref ring idx))
|
|
|
|
(setq idx (1+ idx)))))
|
|
|
|
|
|
|
|
(add-hook 'semantic-before-toplevel-cache-flush-hook
|
2021-03-15 00:08:34 -04:00
|
|
|
#'semantic-mrub-cache-flush-fcn)
|
2009-09-21 02:26:07 +00:00
|
|
|
|
|
|
|
;;; EDIT tracker
|
|
|
|
;;
|
|
|
|
(defvar semantic-mrub-last-overlay nil
|
|
|
|
"The last overlay bumped by `semantic-mru-bookmark-change-hook-fcn'.")
|
|
|
|
|
|
|
|
(defun semantic-mru-bookmark-change-hook-fcn (overlay)
|
|
|
|
"Function set into `semantic-edits-new/move-change-hook's.
|
|
|
|
Argument OVERLAY is the overlay created to mark the change.
|
|
|
|
This function pushes tags onto the tag ring."
|
|
|
|
;; Dup?
|
|
|
|
(when (not (eq overlay semantic-mrub-last-overlay))
|
|
|
|
(setq semantic-mrub-last-overlay overlay)
|
|
|
|
(semantic-mrub-push semantic-mru-bookmark-ring
|
|
|
|
(point)
|
|
|
|
'edit)))
|
|
|
|
|
|
|
|
;;; MINOR MODE
|
|
|
|
;;
|
|
|
|
;; Tracking minor mode.
|
|
|
|
|
|
|
|
(defcustom global-semantic-mru-bookmark-mode nil
|
2009-12-14 04:17:00 +00:00
|
|
|
"If non-nil, enable `semantic-mru-bookmark-mode' globally.
|
|
|
|
When this mode is enabled, Emacs keeps track of which tags have
|
|
|
|
been edited, and you can re-visit them with \\[semantic-mrub-switch-tags]."
|
2009-09-21 02:26:07 +00:00
|
|
|
:group 'semantic
|
|
|
|
:group 'semantic-modes
|
|
|
|
:type 'boolean
|
2010-09-29 21:41:13 -04:00
|
|
|
:require 'semantic/util-modes
|
2021-03-15 00:08:34 -04:00
|
|
|
:initialize #'custom-initialize-default
|
|
|
|
:set (lambda (_sym val)
|
2009-09-21 02:26:07 +00:00
|
|
|
(global-semantic-mru-bookmark-mode (if val 1 -1))))
|
|
|
|
|
|
|
|
;;;###autoload
|
2010-05-01 23:38:19 -04:00
|
|
|
(define-minor-mode global-semantic-mru-bookmark-mode
|
2018-07-01 23:34:53 -04:00
|
|
|
"Toggle global use of option `semantic-mru-bookmark-mode'."
|
2010-05-01 23:38:19 -04:00
|
|
|
:global t :group 'semantic :group 'semantic-modes
|
|
|
|
;; Not needed because it's autoloaded instead.
|
|
|
|
;; :require 'semantic-util-modes
|
|
|
|
(semantic-toggle-minor-mode-globally
|
|
|
|
'semantic-mru-bookmark-mode (if global-semantic-mru-bookmark-mode 1 -1)))
|
2009-09-21 02:26:07 +00:00
|
|
|
|
|
|
|
(defcustom semantic-mru-bookmark-mode-hook nil
|
Remove obsolete leading * from defcustom, defface doc strings.
* lisp/cedet/ede/linux.el, lisp/cedet/ede/project-am.el:
* lisp/cedet/ede/simple.el, lisp/cedet/semantic/bovine/c.el:
* lisp/cedet/semantic/complete.el, lisp/cedet/semantic/db.el:
* lisp/cedet/semantic/decorate/include.el:
* lisp/cedet/semantic/decorate/mode.el, lisp/cedet/semantic/format.el:
* lisp/cedet/semantic/ia.el, lisp/cedet/semantic/idle.el:
* lisp/cedet/semantic/imenu.el, lisp/cedet/semantic/lex-spp.el:
* lisp/cedet/semantic/mru-bookmark.el, lisp/cedet/semantic/sb.el:
* lisp/cedet/srecode/fields.el, lisp/ecomplete.el:
* lisp/gnus/gnus-agent.el, lisp/gnus/gnus-art.el:
* lisp/gnus/gnus-async.el, lisp/gnus/gnus-cache.el:
* lisp/gnus/gnus-cite.el, lisp/gnus/gnus-delay.el:
* lisp/gnus/gnus-diary.el, lisp/gnus/gnus-dup.el:
* lisp/gnus/gnus-fun.el, lisp/gnus/gnus-group.el:
* lisp/gnus/gnus-kill.el, lisp/gnus/gnus-msg.el:
* lisp/gnus/gnus-picon.el, lisp/gnus/gnus-salt.el:
* lisp/gnus/gnus-score.el, lisp/gnus/gnus-start.el:
* lisp/gnus/gnus-sum.el, lisp/gnus/gnus-topic.el:
* lisp/gnus/gnus-util.el, lisp/gnus/gnus-uu.el, lisp/gnus/gnus-win.el:
* lisp/gnus/gnus.el, lisp/gnus/mail-source.el, lisp/gnus/message.el:
* lisp/gnus/mm-url.el, lisp/gnus/mm-uu.el, lisp/gnus/mml.el:
* lisp/gnus/nndiary.el, lisp/gnus/nnir.el, lisp/gnus/nnmail.el:
* lisp/gnus/smiley.el, lisp/gnus/smime.el, lisp/mail/mail-extr.el:
* lisp/mh-e/mh-e.el, lisp/net/mailcap.el, lisp/net/pop3.el:
* lisp/net/starttls.el, lisp/progmodes/cc-vars.el:
* lisp/progmodes/cperl-mode.el, test/manual/cedet/tests/test.el:
Remove obsolete leading * from defcustom, defface doc strings.
2016-06-09 20:13:12 -04:00
|
|
|
"Hook run at the end of function `semantic-mru-bookmark-mode'."
|
2009-09-21 02:26:07 +00:00
|
|
|
:group 'semantic
|
|
|
|
:type 'hook)
|
|
|
|
|
2022-09-13 15:05:28 +02:00
|
|
|
(defvar-keymap semantic-mru-bookmark-mode-map
|
|
|
|
:doc "Keymap for mru-bookmark minor mode."
|
|
|
|
"C-x B" #'semantic-mrub-switch-tags)
|
2009-09-21 02:26:07 +00:00
|
|
|
|
2010-05-01 23:38:19 -04:00
|
|
|
(define-minor-mode semantic-mru-bookmark-mode
|
|
|
|
"Minor mode for tracking tag-based bookmarks automatically.
|
|
|
|
When this mode is enabled, Emacs keeps track of which tags have
|
|
|
|
been edited, and you can re-visit them with \\[semantic-mrub-switch-tags].
|
|
|
|
|
|
|
|
\\{semantic-mru-bookmark-mode-map}
|
2009-09-21 02:26:07 +00:00
|
|
|
|
2018-07-01 23:34:53 -04:00
|
|
|
The minor mode can be turned on only if semantic feature is
|
|
|
|
available and the current buffer was set up for parsing. Return
|
|
|
|
non-nil if the minor mode is enabled."
|
2010-05-01 23:38:19 -04:00
|
|
|
:keymap semantic-mru-bookmark-mode-map
|
2009-09-21 02:26:07 +00:00
|
|
|
(if semantic-mru-bookmark-mode
|
|
|
|
(if (not (and (featurep 'semantic) (semantic-active-p)))
|
|
|
|
(progn
|
|
|
|
;; Disable minor mode if semantic stuff not available
|
|
|
|
(setq semantic-mru-bookmark-mode nil)
|
|
|
|
(error "Buffer %s was not set up for parsing"
|
|
|
|
(buffer-name)))
|
2012-11-12 11:50:08 -05:00
|
|
|
(add-hook 'semantic-edits-new-change-functions
|
2021-03-15 00:08:34 -04:00
|
|
|
#'semantic-mru-bookmark-change-hook-fcn nil t)
|
2009-09-21 02:26:07 +00:00
|
|
|
(add-hook 'semantic-edits-move-change-hooks
|
2021-03-15 00:08:34 -04:00
|
|
|
#'semantic-mru-bookmark-change-hook-fcn nil t))
|
2009-09-21 02:26:07 +00:00
|
|
|
;; Remove hooks
|
2012-11-12 11:50:08 -05:00
|
|
|
(remove-hook 'semantic-edits-new-change-functions
|
2021-03-15 00:08:34 -04:00
|
|
|
#'semantic-mru-bookmark-change-hook-fcn t)
|
2009-09-21 02:26:07 +00:00
|
|
|
(remove-hook 'semantic-edits-move-change-hooks
|
2021-03-15 00:08:34 -04:00
|
|
|
#'semantic-mru-bookmark-change-hook-fcn t)))
|
2009-09-21 02:26:07 +00:00
|
|
|
|
|
|
|
(semantic-add-minor-mode 'semantic-mru-bookmark-mode
|
2010-05-01 23:38:19 -04:00
|
|
|
"k")
|
2009-09-21 02:26:07 +00:00
|
|
|
|
|
|
|
;;; COMPLETING READ
|
|
|
|
;;
|
|
|
|
;; Ask the user for a tag in MRU order.
|
|
|
|
(defun semantic-mrub-read-history nil
|
|
|
|
"History of `semantic-mrub-completing-read'.")
|
|
|
|
|
|
|
|
(defun semantic-mrub-ring-to-assoc-list (ring)
|
|
|
|
"Convert RING into an association list for completion."
|
|
|
|
(let ((idx 0)
|
|
|
|
(len (ring-length ring))
|
|
|
|
(al nil))
|
|
|
|
(while (< idx len)
|
|
|
|
(let ((r (ring-ref ring idx)))
|
2019-06-13 18:01:42 +02:00
|
|
|
(setq al (cons (cons (oref r object-name) r)
|
2009-09-21 02:26:07 +00:00
|
|
|
al)))
|
|
|
|
(setq idx (1+ idx)))
|
|
|
|
(nreverse al)))
|
|
|
|
|
|
|
|
(defun semantic-mrub-completing-read (prompt)
|
|
|
|
"Do a `completing-read' on elements from the mru bookmark ring.
|
2009-09-30 07:55:35 +00:00
|
|
|
Argument PROMPT is the prompt to use when reading."
|
2009-09-21 02:26:07 +00:00
|
|
|
(if (ring-empty-p (oref semantic-mru-bookmark-ring ring))
|
|
|
|
(error "Semantic Bookmark ring is currently empty"))
|
|
|
|
(let* ((ring (oref semantic-mru-bookmark-ring ring))
|
|
|
|
(ans nil)
|
|
|
|
(alist (semantic-mrub-ring-to-assoc-list ring))
|
|
|
|
(first (cdr (car alist)))
|
|
|
|
(semantic-mrub-read-history nil)
|
|
|
|
)
|
|
|
|
;; Don't include the current tag.. only those that come after.
|
|
|
|
(if (semantic-equivalent-tag-p (oref first tag)
|
|
|
|
(semantic-current-tag))
|
|
|
|
(setq first (cdr (car (cdr alist)))))
|
|
|
|
;; Create a fake history list so we don't have to bind
|
|
|
|
;; M-p and M-n to our special cause.
|
|
|
|
(let ((elts (reverse alist)))
|
|
|
|
(while elts
|
|
|
|
(setq semantic-mrub-read-history
|
|
|
|
(cons (car (car elts)) semantic-mrub-read-history))
|
|
|
|
(setq elts (cdr elts))))
|
|
|
|
(setq semantic-mrub-read-history (nreverse semantic-mrub-read-history))
|
|
|
|
|
|
|
|
;; Do the read/prompt
|
|
|
|
(let ((prompt (if first (format "%s (%s): " prompt
|
|
|
|
(semantic-format-tag-name
|
|
|
|
(oref first tag) t)
|
|
|
|
)
|
|
|
|
(concat prompt ": ")))
|
|
|
|
)
|
|
|
|
(setq ans
|
|
|
|
(completing-read prompt alist nil nil nil 'semantic-mrub-read-history)))
|
|
|
|
;; Calculate the return tag.
|
|
|
|
(if (string= ans "")
|
|
|
|
(setq ans first)
|
|
|
|
;; Return the bookmark object.
|
|
|
|
(setq ans (assoc ans alist))
|
|
|
|
(if ans
|
|
|
|
(cdr ans)
|
2011-12-30 17:27:15 -08:00
|
|
|
;; no match. Custom word. Look it up somewhere?
|
2009-09-21 02:26:07 +00:00
|
|
|
nil)
|
|
|
|
)))
|
|
|
|
|
|
|
|
(defun semantic-mrub-switch-tags (tagmark)
|
|
|
|
"Switch tags to TAGMARK.
|
2009-09-30 07:55:35 +00:00
|
|
|
Selects a new tag via prompt through the mru tag ring.
|
2009-09-21 02:26:07 +00:00
|
|
|
Jumps to the tag and highlights it briefly."
|
|
|
|
(interactive (list (semantic-mrub-completing-read "Switch to tag")))
|
|
|
|
(if (not (semantic-bookmark-p tagmark))
|
|
|
|
(signal 'wrong-type-argument tagmark))
|
|
|
|
|
|
|
|
(semantic-mrub-push semantic-mru-bookmark-ring
|
|
|
|
(point)
|
|
|
|
'jump)
|
|
|
|
(semantic-mrub-visit tagmark)
|
|
|
|
)
|
|
|
|
|
|
|
|
;;; Debugging
|
|
|
|
;;
|
|
|
|
(defun semantic-adebug-mrub ()
|
|
|
|
"Display a list of items in the MRU bookmarks list.
|
|
|
|
Useful for debugging mrub problems."
|
|
|
|
(interactive)
|
|
|
|
(require 'eieio-datadebug)
|
|
|
|
(let* ((out semantic-mru-bookmark-ring))
|
|
|
|
(data-debug-new-buffer "*TAG RING ADEBUG*")
|
|
|
|
(data-debug-insert-object-slots out "]")
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'semantic/mru-bookmark)
|
|
|
|
|
|
|
|
;; Local variables:
|
|
|
|
;; generated-autoload-file: "loaddefs.el"
|
|
|
|
;; generated-autoload-load-name: "semantic/mru-bookmark"
|
|
|
|
;; End:
|
|
|
|
|
|
|
|
;;; semantic/mru-bookmark.el ends here
|