From 1914d2e9629a076d33225959a1332dd408527a08 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Mon, 17 May 2021 23:00:15 -0400 Subject: [PATCH] Add java-eval-buffer --- config.org | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/config.org b/config.org index e109b44..ba34383 100644 --- a/config.org +++ b/config.org @@ -547,6 +547,25 @@ Use Emacs globally. Use the Emacs daemon and bind a key in your wm to =emacsclie :straight (git-email :repo "https://git.sr.ht/~yoctocell/git-email") :config (git-email-piem-mode)) #+end_src +** Java +*** Evaluate current buffer +Stolen from https://stackoverflow.com/questions/19953924/how-do-you-run-java-codes-in-emacs +#+begin_src emacs-lisp + (defun java-eval-buffer () + "run current program (that requires no input)" + (interactive) + (let* ((source (file-name-nondirectory buffer-file-name)) + (out (file-name-sans-extension source)) + (class (concat out ".class"))) + (save-buffer) + (shell-command (format "rm -f %s && javac %s" class source)) + (if (file-exists-p class) + (shell-command (format "java %s" out) "*scratch*") + (progn + (set (make-local-variable 'compile-command) + (format "javac %s" source)) + (command-execute 'compile))))) +#+end_src * General text editing ** Indentation Indent after every change. -- 2.39.2