]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/loc-changes/loc-changes.el
loc-changes/loc-changes.el: Fix footer
[gnu-emacs-elpa] / packages / loc-changes / loc-changes.el
index 417f2fe78b29aaac1e6bba2c0683a9c02b33fb77..a269c0a466b129ea1d5a450ade43bd4c032a76af 100644 (file)
@@ -1,25 +1,24 @@
-;;; loc-changes.el --- Helps users and programs keep track of positions even after buffer changes.
+;;; loc-changes.el --- keep track of positions even after buffer changes
 
-;; Author: Rocky Bernstein
-;; Version: 1.1
+;; Copyright (C) 2015 Free Software Foundation, Inc
+
+;; Author: Rocky Bernstein <rocky@gnu.org>
+;; Version: 1.2
 ;; URL: http://github.com/rocky/emacs-loc-changes
 ;; Compatibility: GNU Emacs 24.x
 
-;;  Copyright (C) 2013-2014 Rocky Bernstein <rocky@gnu.org>
-
-;; This program 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.
+;; This program 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.
 
-;; This program 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.
+;; This program 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
-;; along with this program.  If not, see
-;; <http://www.gnu.org/licenses/>.
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -34,9 +33,6 @@
 ;; Another use might be in a compilation buffer for errors and
 ;; warnings which refer to file and line positions.
 
-;; Should be available via Melpa.
-
-
 ;;; Code:
 
 (make-variable-buffer-local 'loc-changes-alist)
@@ -46,6 +42,42 @@ their corresponding markers in the buffer. The 'key' is the line number; the val
 the marker"
   )
 
+(defun loc-changes:follow-mark(event)
+  (interactive "e")
+  (let* ((pos (posn-point (event-end event)))
+        (mark (get-text-property pos 'mark)))
+    (switch-to-buffer-other-window  (marker-buffer mark))
+    (goto-char (marker-position mark))
+    ))
+
+
+(defun loc-changes:alist-describe (&optional opt-buffer)
+  "Display buffer-local variable loc-changes-alist. If BUFFER is
+not given, the current buffer is used. Information is put in an
+internal buffer called *Describe*."
+  (interactive "")
+  (let ((buffer (or opt-buffer (current-buffer)))
+       (alist))
+    (with-current-buffer buffer
+         (setq alist loc-changes-alist)
+         (unless (listp alist) (error "expecting loc-changes-alist to be a list"))
+         )
+    (switch-to-buffer (get-buffer-create "*Describe*"))
+    (setq buffer-read-only 'nil)
+    (delete-region (point-min) (point-max))
+    (dolist (assoc alist)
+         (put-text-property
+          (insert-text-button
+           (format "line %d: %s\n" (car assoc) (cdr assoc))
+           'action 'loc-changes:follow-mark
+           'help-echo "mouse-2: go to this location")
+          (point)
+          'mark (cdr assoc)
+           )
+         )
+    (setq buffer-read-only 't)
+    ))
+
 ;;;###autoload
 (defun loc-changes-goto-line (line-number &optional column-number)
   "Position `point' at LINE-NUMBER of the current buffer. If
@@ -222,5 +254,4 @@ NO-UPDATE is set, no mark is added."
   )
 
 (provide 'loc-changes)
-
 ;;; loc-changes.el ends here