Skip to content

Instantly share code, notes, and snippets.

@i03nomura1y
Created November 1, 2012 07:25
Show Gist options
  • Save i03nomura1y/3992316 to your computer and use it in GitHub Desktop.
Save i03nomura1y/3992316 to your computer and use it in GitHub Desktop.
elisp : check vi swap file
;; if .file.swp exists :
;; set buffer-read-only and ask to user
(defun check-vi-swp-file ()
(let* ((fullpath (file-truename (buffer-file-name)))
(dirpath (file-name-directory fullpath) )
(fname (file-name-nondirectory fullpath) )
(swppath (concat dirpath "." fname ".swp") ))
(if (file-exists-p swppath)
(progn
(setq buffer-read-only 't) ; set Read-Only.
(if (y-or-n-p "vi swap file exists; really edit the buffer? ")
(setq buffer-read-only 'nil) ; set Writable.
)))))
;; (add-hook 'find-file-hooks 'check-vi-swp-file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment