summaryrefslogtreecommitdiff
path: root/tools/dev/svn-entries.el
blob: fff322af9a846816045021adfdf64c80da3da4dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
;;; svn-entries.el --- Display .svn/entries field names to the left

;; Copyright (C) 2007  David Glasser

;; Licensed under the same license as Subversion.

;; Licensed to the Apache Software Foundation (ASF) under one
;; or more contributor license agreements.  See the NOTICE file
;; distributed with this work for additional information
;; regarding copyright ownership.  The ASF licenses this file
;; to you under the Apache License, Version 2.0 (the
;; "License"); you may not use this file except in compliance
;; with the License.  You may obtain a copy of the License at
;;
;;   http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing,
;; software distributed under the License is distributed on an
;; "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
;; KIND, either express or implied.  See the License for the
;; specific language governing permissions and limitations
;; under the License.

;;; Commentary:

;; Display field names to the left of the lines in a .svn/entries
;; buffer. Copy svn-entries.el to your load-path and add to your
;; .emacs:

;;    (require 'svn-entries)

;; After opening or editing an entries file, run

;;   M-x svn-entries-show

;; To hide:

;;   M-x svn-entries-hide

;; (I tried doing this as a minor mode but setting margins during
;; alist initialization didn't work...)

;; Tested on FSF Emacs 22.


(defvar svn-entries-overlays nil "Overlays used in this buffer.")
(make-variable-buffer-local 'svn-entries-overlays)

(defgroup svn-entries nil
  "Show labels to the left of .svn/entries buffers"
  :group 'convenience)

(defface svn-entries
  '((t :inherit shadow))
  "Face for displaying line numbers in the display margin."
  :group 'svn-entries)

(defun svn-entries-set-margins (buf margin)
  (dolist (w (get-buffer-window-list buf nil t))
    (set-window-margins w margin)))

(defun svn-entries-hide ()
  "Delete all overlays displaying labels for this buffer."
  (interactive)
  (mapc #'delete-overlay svn-entries-overlays)
  (setq svn-entries-overlays nil)
  (svn-entries-set-margins (current-buffer) 0)
  (remove-hook 'window-configuration-change-hook
               'svn-entries-after-config t))

(defun svn-entries-show ()
  "Update labels for the current buffer."
  (interactive)
  (svn-entries-update (current-buffer))
  (add-hook 'window-configuration-change-hook
            'svn-entries-after-config nil t))

(defconst svn-entries-labels 
  ["name"
   "kind"
   "revision"
   "url"
   "repos"
   "schedule"
   "text-time"
   "checksum"
   "committed-date"
   "committed-rev"
   "last-author"
   "has-props"
   "has-prop-mods"
   "cachable-props"
   "present-props"
   "conflict-old"
   "conflict-new"
   "conflict-wrk"
   "prop-reject-file"
   "copied"
   "copyfrom-url"
   "copyfrom-rev"
   "deleted"
   "absent"
   "incomplete"
   "uuid"
   "lock-token"
   "lock-owner"
   "lock-comment"
   "lock-creation-date"
   "changelist"
   "keep-local"
   "working-size"
   "depth"])

(defconst svn-entries-margin-width (length "lock-creation-date"))

(defun svn-entries-update (buffer)
  "Update labels for all windows displaying BUFFER."
  (with-current-buffer buffer
    (svn-entries-hide)
    (save-excursion
      (save-restriction
        (widen)
        (let ((last-line (line-number-at-pos (point-max)))
              (field 0)
              (done nil))
          (goto-char (point-min))
          (while (not done)
            (cond ((= (point) 1)
                   (svn-entries-overlay-here "format"))
                  ((= (following-char) 12) ; ^L
                   (setq field 0))
                  ((not (eobp))
                   (svn-entries-overlay-here (elt svn-entries-labels field))
                   (setq field (1+ field))))
            (setq done (> (forward-line) 0))))))
    (svn-entries-set-margins buffer svn-entries-margin-width)))

(defun svn-entries-overlay-here (label)
  (let* ((fmt-label (propertize label 'face 'svn-entries))
         (left-label (propertize " " 'display `((margin left-margin)
                                                ,fmt-label)))
         (ov (make-overlay (point) (point))))
    (push ov svn-entries-overlays)
    (overlay-put ov 'before-string left-label)))

(defun svn-entries-after-config ()
  (walk-windows (lambda (w) (svn-entries-set-margins-if-overlaid (window-buffer))) 
                nil 'visible))

(defun svn-entries-set-margins-if-overlaid (b)
  (with-current-buffer b
    (when svn-entries-overlays
      (svn-entries-set-margins b svn-entries-margin-width))))

(provide 'svn-entries)
;;; svn-entries.el ends here