monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-devel] emacs code for add-change-log-entry


From: Sebastian Rose
Subject: [Monotone-devel] emacs code for add-change-log-entry
Date: Mon, 04 Dec 2006 14:33:28 +0100

This is a first little start of emacs-code, to achieve the task of
writing to _MTN/log if appropriate. Improvements welcome. Just include
this file and use mtn-add-change-log-entry instead of
add-change-log-entry from now on. mtn-add-change-log-entry}}} will try
do the right thing: use ../../_MTN/log if _MTN/ exists in current path
or somewhere up the tree, ./ChangeLog (or better change-log-default-name
as from customize) otherwise. Still your customisations (M-x
customize-group RET change-log RET) work as expected.

I put it in the wiki and it can be found by scrolling
http://venge.net/monotone/wiki/QuickieTasks all to the bottom or go to
http://venge.net/monotone/wiki/ChangeLog. Does
anyone know a better place, where this should be linked on that site?


Here's the code:



;; File:    sr-monotone.el
;; $Revision: 1.1$
;; Date:    2006-12-04
;; Author:  Sebastian Rose <address@hidden>
;; License: GPL
;;
;; Copyright (c) 2006 Sebastian Rose <address@hidden>
;;
;;
;; Provides to funktions:
;;    * mtn-get-parent-directory (child)
;;      returns the parent directory or nil, if there is no parent.
;;      I wrote it, since I could not find a function like this.
;;    * mtn-add-change-log-entry ()
;;      looks for _MTN directory and changes the behaviour of
;;      add-change-log-entry to use /PATH/TO/_MTN as directory
;;      and 'log' as the default filename for the logfile.
;;
;;
;;
;; Usage:
;;
;;                    THE ONE WAY
;; In your .emacs put this line:
;; (require 'sr-monotone)
;; ... and place this file somewhere in your load-path.
;;
;;
;;                    THE OTHER WAY
;; Copy the two functions here and paste them in your .emacs.
;;
;;
;;
;; Bind any key you like to mtn-add-change-log-entry. From now on,
;; only use mtn-add-change-log-entry. It detects automagically the
;; right way to call add-change-log-entry.

(provide 'sr-monotone)


(defun mtn-get-parent-directory (child)
  "Retruns the parent directory or nil, if there is no parent.
Parent has always a trailing slash, or what ever is your systems
file separtor.
Improvements and suggestions to address@hidden"
  (if (file-regular-p child)
      (file-name-as-directory (file-name-directory child))
    ; this is else:
    (let ((child (file-name-as-directory child)))
      (let ((dir (file-name-as-directory (expand-file-name child)))
            (parent (file-truename
                     (file-name-as-directory (expand-file-name (concat
child ".."))))))
        (if (string= dir parent)
            nil
          parent)))))



(defun mtn-add-change-log-entry()emacs/lisp/
  "Searches in buffers default-directory and above for a directory
named '_MTN'. If it exists, monotone-add-change-log-entry calls
add-change-log-entry with apropriate arguments, but currently not
interactively (maybe I'll add a switch for this in the future).
Otherwise interactively calls add-change-log-entry the normal way.
So one can just bind this function to the keys, that call
add-change-log-entry now, and it will work just fine.

Improvements and suggestions to address@hidden"
(interactive)emacs/lisp/
  (let ((filename buffer-file-name)
        (is-mtn-dir nil)
        (original-default-directory default-directory)
        (original-change-log-filename nil))
    (if (boundp 'change-log-default-name)
        (setq original-change-log-filename change-log-default-name))
    (unwind-protect
        (progn
          (if filename
              (progn
                (catch 'done
                  (while (setq filename (mtn-get-parent-directory
filename))
                    (if (file-directory-p (concat filename "_MTN"))
                        (progn
                          (setq change-log-default-name "log")
                                        ;(setq default-directory (concat
filename "_MTN"))
                          (setq is-mtn-dir (concat filename "_MTN"))
                          (throw 'done 'is-mtn-dir)))))
                (if is-mtn-dir
                    (let ((default-directory is-mtn-dir))
                      (call-interactively 'add-change-log-entry))
                  (call-interactively 'add-change-log-entry))
                )))
          (setq default-directory original-default-directory)
          (setq change-log-default-name original-change-log-filename)
          )))
-- 
Sebastian Rose <address@hidden>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]