Skip to content

Instantly share code, notes, and snippets.

@alexover1
Last active September 15, 2026 05:24
Show Gist options
  • Select an option

  • Save alexover1/c5fa7de901c63516b483d900e7cdbc27 to your computer and use it in GitHub Desktop.

Select an option

Save alexover1/c5fa7de901c63516b483d900e7cdbc27 to your computer and use it in GitHub Desktop.
;; Automatically loads the compile command from a file in the current working directory.
(defun alex/default-compile-command ()
(interactive)
(let ((file (expand-file-name ".compile-command" default-directory)))
(when (file-readable-p file)
(setq-local compile-command
(string-trim
(with-temp-buffer
(insert-file-contents file)
(buffer-string))))
(message "Command set to: %s" compile-command))))
;; Recompiles if compile-command is set, or else tries to set it to the contents of .compile-command.
(defun alex/recompile ()
(interactive)
(when (or (null compile-command)
(string-empty-p compile-command))
(alex/default-compile-command))
(recompile))
(setq-default compile-command nil)
;; Enable compilation-mode keyboard shortcuts.
(keymap-global-set "C-c c" #'compile)
(keymap-global-set "C-c r" #'alex/recompile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment