all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* numbered backups
@ 2014-05-21  2:13 Steven Arntson
  2014-05-21 17:26 ` Michael Heerdegen
  0 siblings, 1 reply; 9+ messages in thread
From: Steven Arntson @ 2014-05-21  2:13 UTC (permalink / raw)
  To: help-gnu-emacs

I know I read how to do this somewhere, but can't find it now. I'd like
emacs to name my backup files not as

file.org.~1~
file.org.~2~

but rather as

file.org.~001~
file.org.~002~

is there a variable I could call up from M-x customize to influence this
behavior?

Thank you!
Steven Arntson




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

* Re: numbered backups
       [not found] <mailman.1717.1400638422.1147.help-gnu-emacs@gnu.org>
@ 2014-05-21  2:37 ` Pascal J. Bourguignon
  2014-05-21  3:00   ` Steven Arntson
       [not found]   ` <mailman.1721.1400641272.1147.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: Pascal J. Bourguignon @ 2014-05-21  2:37 UTC (permalink / raw)
  To: help-gnu-emacs

Steven Arntson <steven@stevenarntson.com> writes:

> I know I read how to do this somewhere, but can't find it now. I'd like
> emacs to name my backup files not as
>
> file.org.~1~
> file.org.~2~
>
> but rather as
>
> file.org.~001~
> file.org.~002~
>
> is there a variable I could call up from M-x customize to influence this
> behavior?

See the variable make-backup-file-name-function 
and the function make-backup-file-name

-- 
__Pascal Bourguignon__
http://www.informatimago.com/
"Le mercure monte ?  C'est le moment d'acheter !"


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

* Re: numbered backups
  2014-05-21  2:37 ` numbered backups Pascal J. Bourguignon
@ 2014-05-21  3:00   ` Steven Arntson
       [not found]   ` <mailman.1721.1400641272.1147.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Steven Arntson @ 2014-05-21  3:00 UTC (permalink / raw)
  To: help-gnu-emacs

"Pascal J. Bourguignon" <pjb@informatimago.com> writes:

> Steven Arntson <steven@stevenarntson.com> writes:
>
>> I know I read how to do this somewhere, but can't find it now. I'd like
>> emacs to name my backup files not as
>>
>> file.org.~1~
>> file.org.~2~
>>
>> but rather as
>>
>> file.org.~001~
>> file.org.~002~
>>
>> is there a variable I could call up from M-x customize to influence this
>> behavior?
>
> See the variable make-backup-file-name-function 
> and the function make-backup-file-name

This looks promising, but I'm too much of a beginner to accomplish much
with it! Under "value menu" for "Make Backup File Name Function" it asks
me, "Your function: ______". I don't know what to put there to achieve
my desired result.




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

* Re: numbered backups
       [not found]   ` <mailman.1721.1400641272.1147.help-gnu-emacs@gnu.org>
@ 2014-05-21  4:14     ` Pascal J. Bourguignon
  2014-05-21 16:21       ` Steven Arntson
  0 siblings, 1 reply; 9+ messages in thread
From: Pascal J. Bourguignon @ 2014-05-21  4:14 UTC (permalink / raw)
  To: help-gnu-emacs

Steven Arntson <steven@stevenarntson.com> writes:

> "Pascal J. Bourguignon" <pjb@informatimago.com> writes:
>
>> Steven Arntson <steven@stevenarntson.com> writes:
>>
>>> I know I read how to do this somewhere, but can't find it now. I'd like
>>> emacs to name my backup files not as
>>>
>>> file.org.~1~
>>> file.org.~2~
>>>
>>> but rather as
>>>
>>> file.org.~001~
>>> file.org.~002~
>>>
>>> is there a variable I could call up from M-x customize to influence this
>>> behavior?
>>
>> See the variable make-backup-file-name-function 
>> and the function make-backup-file-name
>
> This looks promising, but I'm too much of a beginner to accomplish much
> with it! Under "value menu" for "Make Backup File Name Function" it asks
> me, "Your function: ______". I don't know what to put there to achieve
> my desired result.

Reading the source of make-backup-file-name we can see that it's
actually the function find-backup-file-name that formats the backup file
names.


This function has to be changed to allow for smooth migration from
.~%d~ to .~%03d~ version numbers, and to allow parameterisation of the
version number format. 

Here is the new find-backup-file-name function, with the additions.


(defcustom backup-file-version-format "%d"
  "format specifier for version numbers in backup files."
  :group 'backup
  :type 'string)

(defun format-backup-file-name (name &optional version)
  (if version
      (concat name ".~" (format backup-file-version-format version) "~")
      (concat name ".~")))

(defun find-backup-file-name (fn)
  "Find a file name for a backup file FN, and suggestions for deletions.
Value is a list whose car is the name for the backup file
and whose cdr is a list of old versions to consider deleting now.
If the value is nil, don't make a backup.
Uses `backup-directory-alist' in the same way as does
`make-backup-file-name'."
  (let ((handler (find-file-name-handler fn 'find-backup-file-name)))
    ;; Run a handler for this function so that ange-ftp can refuse to do it.
    (if handler
        (funcall handler 'find-backup-file-name fn)
        (if (or (eq version-control 'never)
                ;; We don't support numbered backups on plain MS-DOS
                ;; when long file names are unavailable.
                (and (eq system-type 'ms-dos)
                     (not (msdos-long-file-names))))
            (list (make-backup-file-name fn))
            (let* ((basic-name (make-backup-file-name-1 fn))
                   (base-versions (format-backup-file-name (file-name-nondirectory basic-name)))
                   (backup-extract-version-start (length base-versions))
                   (high-water-mark 0)
                   (number-to-delete 0)
                   possibilities deserve-versions-p versions)
              (condition-case ()
                              (setq possibilities (file-name-all-completions
                                                   base-versions
                                                   (file-name-directory basic-name))
                                    versions (sort (mapcar
                                                    (lambda (file)
                                                      (cons (backup-extract-version file)
                                                            file))
                                                    possibilities)
                                                   (lambda (a b) (< (car a) (car b))))
                                    high-water-mark (apply (function max) 0 (mapcar (function car) versions))
                                    deserve-versions-p (or version-control
                                                           (> high-water-mark 0))
                                    number-to-delete (- (length versions)
                                                        kept-old-versions
                                                        kept-new-versions
                                                        -1))
                              (file-error (setq possibilities nil)))
              (if (not deserve-versions-p)
                  (list (make-backup-file-name fn))
                  (cons (format-backup-file-name basic-name (1+ high-water-mark))
                        (if (and (> number-to-delete 0)
                                 ;; Delete nothing if there is overflow
                                 ;; in the number of versions to keep.
                                 (>= (+ kept-new-versions kept-old-versions -1) 0))
                            (let ((new-versions (let ((v (nthcdr kept-old-versions versions)))
                                                  (rplacd (nthcdr (1- number-to-delete) v) ())
                                                  v)))
                              (mapcar (function cdr) new-versions))))))))))


So now you can change the format:

(setf backup-file-version-format "%03d")
(find-backup-file-name "/home/pjb/scratch.txt")
--> ("/home/pjb/scratch.txt.~013~" "scratch.txt.~4~")


-- 
__Pascal Bourguignon__
http://www.informatimago.com/
"Le mercure monte ?  C'est le moment d'acheter !"


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

* Re: numbered backups
  2014-05-21  4:14     ` Pascal J. Bourguignon
@ 2014-05-21 16:21       ` Steven Arntson
  0 siblings, 0 replies; 9+ messages in thread
From: Steven Arntson @ 2014-05-21 16:21 UTC (permalink / raw)
  To: help-gnu-emacs

"Pascal J. Bourguignon" <pjb@informatimago.com> writes:

> Steven Arntson <steven@stevenarntson.com> writes:
>
>> "Pascal J. Bourguignon" <pjb@informatimago.com> writes:
>>
>>> Steven Arntson <steven@stevenarntson.com> writes:
>>>
>>>> I know I read how to do this somewhere, but can't find it now. I'd
>>>> like
>>>> emacs to name my backup files not as
>>>>
>>>> file.org.~1~
>>>> file.org.~2~
>>>>
>>>> but rather as
>>>>
>>>> file.org.~001~
>>>> file.org.~002~
>>>>
>>>> is there a variable I could call up from M-x customize to
>>>> influence this
>>>> behavior?
>>>
>>> See the variable make-backup-file-name-function 
>>> and the function make-backup-file-name
>>
>> This looks promising, but I'm too much of a beginner to accomplish much
>> with it! Under "value menu" for "Make Backup File Name Function" it asks
>> me, "Your function: ______". I don't know what to put there to achieve
>> my desired result.
>
> Reading the source of make-backup-file-name we can see that it's
> actually the function find-backup-file-name that formats the backup file
> names.
>
>
> This function has to be changed to allow for smooth migration from
> .~%d~ to .~%03d~ version numbers, and to allow parameterisation of the
> version number format. 
>
> Here is the new find-backup-file-name function, with the additions.
>
>
> (defcustom backup-file-version-format "%d"
>   "format specifier for version numbers in backup files."
>   :group 'backup
>   :type 'string)
>
> (defun format-backup-file-name (name &optional version)
>   (if version
>       (concat name ".~" (format backup-file-version-format version) "~")
>       (concat name ".~")))
>
> (defun find-backup-file-name (fn)
>   "Find a file name for a backup file FN, and suggestions for deletions.
> Value is a list whose car is the name for the backup file
> and whose cdr is a list of old versions to consider deleting now.
> If the value is nil, don't make a backup.
> Uses `backup-directory-alist' in the same way as does
> `make-backup-file-name'."
>   (let ((handler (find-file-name-handler fn 'find-backup-file-name)))
>     ;; Run a handler for this function so that ange-ftp can refuse to do it.
>     (if handler
>         (funcall handler 'find-backup-file-name fn)
>         (if (or (eq version-control 'never)
>                 ;; We don't support numbered backups on plain MS-DOS
>                 ;; when long file names are unavailable.
>                 (and (eq system-type 'ms-dos)
>                      (not (msdos-long-file-names))))
>             (list (make-backup-file-name fn))
>             (let* ((basic-name (make-backup-file-name-1 fn))
>                    (base-versions (format-backup-file-name (file-name-nondirectory basic-name)))
>                    (backup-extract-version-start (length base-versions))
>                    (high-water-mark 0)
>                    (number-to-delete 0)
>                    possibilities deserve-versions-p versions)
>               (condition-case ()
>                               (setq possibilities (file-name-all-completions
>                                                    base-versions
>                                                    (file-name-directory basic-name))
>                                     versions (sort (mapcar
>                                                     (lambda (file)
>                                                       (cons (backup-extract-version file)
>                                                             file))
>                                                     possibilities)
>                                                    (lambda (a b) (< (car a) (car b))))
>                                     high-water-mark (apply (function max) 0 (mapcar (function car) versions))
>                                     deserve-versions-p (or version-control
>                                                            (> high-water-mark 0))
>                                     number-to-delete (- (length versions)
>                                                         kept-old-versions
>                                                         kept-new-versions
>                                                         -1))
>                               (file-error (setq possibilities nil)))
>               (if (not deserve-versions-p)
>                   (list (make-backup-file-name fn))
>                   (cons (format-backup-file-name basic-name (1+ high-water-mark))
>                         (if (and (> number-to-delete 0)
>                                  ;; Delete nothing if there is overflow
>                                  ;; in the number of versions to keep.
>                                  (>= (+ kept-new-versions kept-old-versions -1) 0))
>                             (let ((new-versions (let ((v (nthcdr kept-old-versions versions)))
>                                                   (rplacd (nthcdr (1- number-to-delete) v) ())
>                                                   v)))
>                               (mapcar (function cdr) new-versions))))))))))
>
>
> So now you can change the format:
>
> (setf backup-file-version-format "%03d")
> (find-backup-file-name "/home/pjb/scratch.txt")
> --> ("/home/pjb/scratch.txt.~013~" "scratch.txt.~4~")

This is way over my head, but I will make a try to get it working, thank
you!

Steven




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

* Re: numbered backups
  2014-05-21  2:13 Steven Arntson
@ 2014-05-21 17:26 ` Michael Heerdegen
  2014-05-21 18:01   ` Steven Arntson
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Heerdegen @ 2014-05-21 17:26 UTC (permalink / raw)
  To: help-gnu-emacs

Steven Arntson <steven@stevenarntson.com> writes:

> file.org.~001~
> file.org.~002~

BTW, if your problem is about how your backup files are sorted in dired,
have a look at the ls -v flag (sort by version) - it works with dired.

Michael.




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

* Re: numbered backups
  2014-05-21 17:26 ` Michael Heerdegen
@ 2014-05-21 18:01   ` Steven Arntson
  2014-05-21 20:27     ` Michael Heerdegen
  0 siblings, 1 reply; 9+ messages in thread
From: Steven Arntson @ 2014-05-21 18:01 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Steven Arntson <steven@stevenarntson.com> writes:
>
>> file.org.~001~
>> file.org.~002~
>
> BTW, if your problem is about how your backup files are sorted in dired,
> have a look at the ls -v flag (sort by version) - it works with dired.
>
> Michael.

Hi Michael,

Yes, that's exactly the behavior I'm looking for! I tried it in eshell,
and it worked perfectly. How do I get dired to act like that?

Thank you!
steven




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

* Re: numbered backups
  2014-05-21 18:01   ` Steven Arntson
@ 2014-05-21 20:27     ` Michael Heerdegen
  2014-05-21 22:37       ` Steven Arntson
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Heerdegen @ 2014-05-21 20:27 UTC (permalink / raw)
  To: help-gnu-emacs

Steven Arntson <steven@stevenarntson.com> writes:

> Yes, that's exactly the behavior I'm looking for! I tried it in eshell,
> and it worked perfectly. How do I get dired to act like that?

You just need to set the default value of `dired-listing-switches'
accordingly and add the -v flag, e.g.

    (setq-default dired-listing-switches "-ahlv")

But also note: when I used that some while ago (now I use always version
control), I saw that -v was incompatible or didn't work so nicely with
some other ls options - I don't know the details anymore.  But in
general, it works well with dired, also s (`dired-sort-toggle-or-edit')
should work ok with it.

Michael.




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

* Re: numbered backups
  2014-05-21 20:27     ` Michael Heerdegen
@ 2014-05-21 22:37       ` Steven Arntson
  0 siblings, 0 replies; 9+ messages in thread
From: Steven Arntson @ 2014-05-21 22:37 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Steven Arntson <steven@stevenarntson.com> writes:
>
>> Yes, that's exactly the behavior I'm looking for! I tried it in eshell,
>> and it worked perfectly. How do I get dired to act like that?
>
> You just need to set the default value of `dired-listing-switches'
> accordingly and add the -v flag, e.g.
>
>     (setq-default dired-listing-switches "-ahlv")
>
> But also note: when I used that some while ago (now I use always version
> control), I saw that -v was incompatible or didn't work so nicely with
> some other ls options - I don't know the details anymore.  But in
> general, it works well with dired, also s (`dired-sort-toggle-or-edit')
> should work ok with it.
>
> Michael.

I added "v" through the customize menu, and it seems to be working
perfectly. Thank you very much!

-Steven




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

end of thread, other threads:[~2014-05-21 22:37 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1717.1400638422.1147.help-gnu-emacs@gnu.org>
2014-05-21  2:37 ` numbered backups Pascal J. Bourguignon
2014-05-21  3:00   ` Steven Arntson
     [not found]   ` <mailman.1721.1400641272.1147.help-gnu-emacs@gnu.org>
2014-05-21  4:14     ` Pascal J. Bourguignon
2014-05-21 16:21       ` Steven Arntson
2014-05-21  2:13 Steven Arntson
2014-05-21 17:26 ` Michael Heerdegen
2014-05-21 18:01   ` Steven Arntson
2014-05-21 20:27     ` Michael Heerdegen
2014-05-21 22:37       ` Steven Arntson

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.