reddit / emacs

Opening files without activating any modes

danderzei · 2022-12-07 01:41
I have a [function in a package](https://github.com/pprevos/citar-denote/blob/185ab89244deda00770bd44c3fee20400091a9df/citar-denote.el#L76) I am working on that reads a bunch of Org files, extracts metadata and saves that in a list. The problem I am facing is that Org mode enables all minor modes (such as LaTeX preview) while reading the file. This makes the function slow. I also need to manually kill these files. I only want their metadata. Is there a way to temporarily open a file without activating any modes to just extract data I need and close it? Something like: (with-temp-buffer FILE-NAME (CODE)) ​
L-Szos · 2022-12-07 02:00
The function `find-file-literally` should open a file in fundamental mode.
ieure · 2022-12-07 02:05
You can also create a temp buffer and `insert-file-contents`. Further, you could erase the buffer when you're done and insert another file, if you're processing more than one.
danderzei · 2022-12-07 02:42
> find-file-literally Excellent - massive speed improvement. Thanks!
ljgatreddit · 2022-12-07 06:39
(let ((buffer (find-file-literally "path/to/file.org"))) (with-current-buffer buffer (goto-char (point-min)) ;; Extract metadata here ) (kill-buffer buffer))