From cc47c443a3f86aa66d2719ee57c0e6e728ee655e Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 22 Oct 2026 13:02:16 +1300 Subject: feat: Included the emacs config Some packages are built with nix and some are still built with emacs --- modules/home-manager/emacs/config/lisp/qalc.el | 64 ++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 modules/home-manager/emacs/config/lisp/qalc.el (limited to 'modules/home-manager/emacs/config/lisp/qalc.el') diff --git a/modules/home-manager/emacs/config/lisp/qalc.el b/modules/home-manager/emacs/config/lisp/qalc.el new file mode 100644 index 0000000..8f344ed --- /dev/null +++ b/modules/home-manager/emacs/config/lisp/qalc.el @@ -0,0 +1,64 @@ +(defvar qalc-cli-file-path "" + "Path to the program used by `run-qalc'") + +(defvar qalc-cli-arguments '() + "Commandline arguments to pass to `qalc-cli'.") + +(defvar qalc-mode-map + (let ((map (nconc (make-sparse-keymap) comint-mode-map))) + ;; example definition + (define-key map "\t" 'completion-at-point) + map) + "Basic mode map for `run-qalc'.") + +(defvar qalc-prompt-regexp "^\\(?:>\\)" + "Prompt for `run-qalc'.") + +(defvar qalc-buffer-name "*Qalc*" + "Name of the buffer to use for the `run-qalc' comint instance.") + +(defun run-qalc () + "Run an inferior instance of `qalc-cli' inside Emacs." + (interactive) + (let* ((qalc-program (executable-find "qalc")) + (buffer (get-buffer-create qalc-buffer-name)) + (proc-alive (comint-check-proc buffer)) + (process (get-buffer-process buffer))) + ;; if the process is dead then re-create the process and reset the + ;; mode. + (unless proc-alive + (with-current-buffer buffer + (apply 'make-comint-in-buffer "Qalc" buffer + qalc-program '() qalc-cli-arguments) + (qalc-mode))) + ;; Regardless, provided we have a valid buffer, we pop to it. + (when buffer + (pop-to-buffer buffer)))) + +(defun qalc--initialize () + "Helper function to initialize Qalc." + (setq comint-process-echoes nil) + (setq comint-use-prompt-regexp t) + (setq comint-prompt-read-only t) + (add-hook 'comint-preoutput-filter-functions 'comint-set-text-read-only)) + + +(defun comint-set-text-read-only (text) + (propertize text 'read-only t)) + +(add-hook 'qalc-mode-hook 'qalc--initialize) + +(define-derived-mode qalc-mode comint-mode "Qalc" + "Major mode for `run-qalc'. + +\\" + ;; this sets up the prompt so it matches > + (setq comint-prompt-regexp qalc-prompt-regexp) + ;; this makes it read only; a contentious subject as some prefer the + ;; buffer to be overwritable. + (setq comint-prompt-read-only t) + ;; this makes it so commands like M-{ and M-} work. + (set (make-local-variable 'paragraph-separate) "\\'") + (set (make-local-variable 'paragraph-start) qalc-prompt-regexp)) + +(provide 'qalc) -- cgit v1.3.1