4

I want the backup files to be created in sub-directories of the files being edited, and I have created a function returns that directory.

(defun tempfilepath ()
  (interactive)
  (concat (file-name-directory buffer-file-name) "./editorbackups")
)

So I need backup-directory-alist to be something like

(setq backup-directory-alist `("." . tempfilepath))

where tempfilepath will be evaluated when the file at runtime so all the backup files are saved under the files folders.

I am not sure how to get the syntax right and the role make-backup-file-name-function if it is necessary in this case.

4

Just use relative directory name

(setq backup-directory-alist '(("." . "editorbackups")))

Function make-backup-file-name-1 will make directory name relative to file's directory and create it:

;; If backup-directory is relative, it should be relative to the
;; file's directory.  By expanding explicitly here, we avoid
;; depending on default-directory.
(if backup-directory
    (setq abs-backup-directory
          (expand-file-name backup-directory
                            (file-name-directory file))))
(if (and abs-backup-directory (not (file-exists-p abs-backup-directory)))
    (condition-case nil
        (make-directory abs-backup-directory 'parents)
      (file-error (setq backup-directory nil
                        abs-backup-directory nil))))

Also make sure that variable make-backup-file-name-function is set to make-backup-file-name--default-function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.