Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply elisp function to any file

Tags:

emacs

elisp

How to apply an elisp function to a specific file, which is not in an open buffer?

Eg (my/apply delete-duplicate-lines "~/tmp")

like image 417
xged Avatar asked Jan 08 '23 13:01

xged


2 Answers

I think you want to do

(with-current-buffer (find-file-noselect "~/tmp")
  (delete-duplicate-lines (point-min) (point-max))
  (save-buffer))

If you want more information on how to programmatically operate on buffer contents read this section of the manual

like image 155
PuercoPop Avatar answered Jan 18 '23 19:01

PuercoPop


If you want also to cleanup the buffer etc, you could use

(let ((file "~/tmp"))
  (with-temp-file file
    (insert-file-contents file)
    (delete-duplicate-lines (point-min) (point-max))))
like image 26
Michael Albinus Avatar answered Jan 18 '23 19:01

Michael Albinus