Subversion branch in mode

If the file is located in a directory supported by the Subversion repository, ending either with trunk, or branches/X, as a conclusion, trunkor Xin the mode line as SVN-trunkor SVN-Xsimilar to what is shown in Git-backed files, usually like Git-master.

+4
source share
2 answers

Determining SVN Status

I don't know any built-in ways to do this, but you can write your own code for this purpose.

vc-svn-repository-name vc-backend , SVN, VC:

(defun lunaryorn-vc-mode-line ()
  (let ((backend (vc-backend (buffer-file-name))))
    (if (eq backend 'SVN)
        (let ((url (vc-svn-repository-hostname (buffer-file-name))))
          (cond
           ((string-match-p "/trunk/" url) "SVN-trunk")
           ((string-match "/branches/\\([^/]+\\)/" url)
            (concat "SVN-" (match-string 1 url)))
           (t vc-mode)))
      ;; Use default mode text for other backends
      vc-mode)))

SVN, URL- . vc-svn-repository-hostname, URL- .

URL- , VC , vc-mode.

, mode-line-format:

(setq-default mode-line-format
              '(…
                (vc-mode (" " (:eval (lunaryorn-vc-mode-line))))
                …))

mode-line-format -, setq-default . , vc-mode, , , , . . " " .

, . , mode-line-format (vc-mode vc-mode) . VC .

+5

:

(defun vc-svn-mode-line-string (file)
  (format "SVN-%s" (vc-svn-current-branch-name file)))

, vc-svn-current-branch-name, . , -

(defun vc-svn-current-branch-name (file)
  (with-temp-buffer
    (setq default-directory (file-name-directory file))
    (vc-svn-command t t file "info")
    ...extract the branch name from the info in current buffer..
    ))
+3

All Articles