Follow-up to r29036: Now that the "mergeinfo" transaction file is no
[svn.git] / tools / dev / svn-entries.el
blob8af9e347158f3e2f2defb512b384c5c678386c89
1 ;;; svn-entries.el --- Display .svn/entries field names to the left
3 ;; Copyright (C) 2007 David Glasser
5 ;; Licensed under the same license as Subversion.
7 ;;; Commentary:
9 ;; Display field names to the left of the lines in a .svn/entries
10 ;; buffer. Copy svn-entries.el to your load-path and add to your
11 ;; .emacs:
13 ;; (require 'svn-entries)
15 ;; After opening or editing an entries file, run
17 ;; M-x svn-entries-show
19 ;; To hide:
21 ;; M-x svn-entries-hide
23 ;; (I tried doing this as a minor mode but setting margins during
24 ;; alist initialization didn't work...)
26 ;; Tested on FSF Emacs 22.
29 (defvar svn-entries-overlays nil "Overlays used in this buffer.")
30 (make-variable-buffer-local 'svn-entries-overlays)
32 (defgroup svn-entries nil
33 "Show labels to the left of .svn/entries buffers"
34 :group 'convenience)
36 (defface svn-entries
37 '((t :inherit shadow))
38 "Face for displaying line numbers in the display margin."
39 :group 'svn-entries)
41 (defun svn-entries-set-margins (buf margin)
42 (dolist (w (get-buffer-window-list buf nil t))
43 (set-window-margins w margin)))
45 (defun svn-entries-hide ()
46 "Delete all overlays displaying labels for this buffer."
47 (interactive)
48 (mapc #'delete-overlay svn-entries-overlays)
49 (setq svn-entries-overlays nil)
50 (svn-entries-set-margins (current-buffer) 0)
51 (remove-hook 'window-configuration-change-hook
52 'svn-entries-after-config t))
54 (defun svn-entries-show ()
55 "Update labels for the current buffer."
56 (interactive)
57 (svn-entries-update (current-buffer))
58 (add-hook 'window-configuration-change-hook
59 'svn-entries-after-config nil t))
61 (defconst svn-entries-labels
62 ["name"
63 "kind"
64 "revision"
65 "url"
66 "repos"
67 "schedule"
68 "text-time"
69 "checksum"
70 "committed-date"
71 "committed-rev"
72 "last-author"
73 "has-props"
74 "has-prop-mods"
75 "cachable-props"
76 "present-props"
77 "conflict-old"
78 "conflict-new"
79 "conflict-wrk"
80 "prop-reject-file"
81 "copied"
82 "copyfrom-url"
83 "copyfrom-rev"
84 "deleted"
85 "absent"
86 "incomplete"
87 "uuid"
88 "lock-token"
89 "lock-owner"
90 "lock-comment"
91 "lock-creation-date"
92 "changelist"
93 "keep-local"
94 "working-size"
95 "depth"])
97 (defconst svn-entries-margin-width (length "lock-creation-date"))
99 (defun svn-entries-update (buffer)
100 "Update labels for all windows displaying BUFFER."
101 (with-current-buffer buffer
102 (svn-entries-hide)
103 (save-excursion
104 (save-restriction
105 (widen)
106 (let ((last-line (line-number-at-pos (point-max)))
107 (field 0)
108 (done nil))
109 (goto-char (point-min))
110 (while (not done)
111 (cond ((= (point) 1)
112 (svn-entries-overlay-here "format"))
113 ((= (following-char) 12) ; ^L
114 (setq field 0))
115 ((not (eobp))
116 (svn-entries-overlay-here (elt svn-entries-labels field))
117 (setq field (1+ field))))
118 (setq done (> (forward-line) 0))))))
119 (svn-entries-set-margins buffer svn-entries-margin-width)))
121 (defun svn-entries-overlay-here (label)
122 (let* ((fmt-label (propertize label 'face 'svn-entries))
123 (left-label (propertize " " 'display `((margin left-margin)
124 ,fmt-label)))
125 (ov (make-overlay (point) (point))))
126 (push ov svn-entries-overlays)
127 (overlay-put ov 'before-string left-label)))
129 (defun svn-entries-after-config ()
130 (walk-windows (lambda (w) (svn-entries-set-margins-if-overlaid (window-buffer)))
131 nil 'visible))
133 (defun svn-entries-set-margins-if-overlaid (b)
134 (with-current-buffer b
135 (when svn-entries-overlays
136 (svn-entries-set-margins b svn-entries-margin-width))))
138 (provide 'svn-entries)
139 ;;; svn-entries.el ends here