all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to test if a directory is under version control ?
@ 2003-11-05 12:11 François Fleuret
  2003-11-05 14:15 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: François Fleuret @ 2003-11-05 12:11 UTC (permalink / raw)


Hi people,

I am trying to write a simple function that would alert me when I edit
a file which is not under version-control, while the directory is.

To test if the file is under VC, I found vc-registered. For the
directory, if I do not find a more elegant way, I will end up looking
for a 'CVS' directory at the file's location, as I use CVS. But I
thought that there may be better solution ...

Any advice ?

Thanks in advance,

FF

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to test if a directory is under version control ?
  2003-11-05 12:11 How to test if a directory is under version control ? François Fleuret
@ 2003-11-05 14:15 ` Stefan Monnier
  2003-11-06 11:30   ` François Fleuret
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2003-11-05 14:15 UTC (permalink / raw)


> I am trying to write a simple function that would alert me when I edit
> a file which is not under version-control, while the directory is.

> To test if the file is under VC, I found vc-registered. For the
> directory, if I do not find a more elegant way, I will end up looking
> for a 'CVS' directory at the file's location, as I use CVS. But I
> thought that there may be better solution ...

VC has two related operations: `responsible-p' and `could-register'.
They're used in the function `vc-responsible-backend'.  But this function
will not give you what you want because it'll always find a backend (in the
worst case it'll just use RCS which does not need any `RCS' subdirectory and
is thus always potentially ready to control a file).

I guess your best bet is something like:

   (defun my-vc-responsible-backend (file)
     "Return the backend responsible for the unregistered FILE.
   Like `vc-responsible-backend' but only returns a responsible backend."
     (let ((bs vc-handled-backends))
       (while (consp bs)
         (setq bs 
               (if (vc-call-backend (car bs) 'responsible-p file)
                   (car bs)
                 (cdr bs))))
       bs))


-- Stefan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to test if a directory is under version control ?
  2003-11-05 14:15 ` Stefan Monnier
@ 2003-11-06 11:30   ` François Fleuret
  0 siblings, 0 replies; 3+ messages in thread
From: François Fleuret @ 2003-11-06 11:30 UTC (permalink / raw)


Hi,

Stefan Monnier wrote on 05 Nov 2003 15:15:07 MET:

> VC has two related operations: `responsible-p' and `could-register'.
>  [ ... snip snip ...]

Thanks Stefan.

I finally wrote the following:

>> ;; This function displays an alarm if the file we are editing is not
>> ;; under CVS while the directory is.
>> 
>> (require 'vc-cvs)
>> 
>> (defun check-under-cvs ()
>>   (when (and buffer-file-name
>>              (not (vc-cvs-registered buffer-file-name))
>>              (vc-cvs-responsible-p buffer-file-name))
>>     (message "*Warning* %s is not under CVS" buffer-file-name)
>>     ))
>> 
>> (add-hook 'find-file-hooks 'check-under-cvs)

Which seems to work fine.

Regards,

-- 
François Fleuret

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-11-06 11:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-05 12:11 How to test if a directory is under version control ? François Fleuret
2003-11-05 14:15 ` Stefan Monnier
2003-11-06 11:30   ` François Fleuret

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.