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.
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
13 ;; (require 'svn-entries)
15 ;; After opening or editing an entries file, run
17 ;; M-x svn-entries-show
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"
37 '((t :inherit shadow
))
38 "Face for displaying line numbers in the display margin."
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."
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."
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
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
106 (let ((last-line (line-number-at-pos (point-max)))
109 (goto-char (point-min))
112 (svn-entries-overlay-here "format"))
113 ((= (following-char) 12) ; ^L
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
)
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)))
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