diff options
| author | Dylan <boss@tehbox.org> | 2026-10-22 13:02:16 +1300 |
|---|---|---|
| committer | Dylan <boss@tehbox.org> | 2026-10-22 17:19:36 +1300 |
| commit | cc47c443a3f86aa66d2719ee57c0e6e728ee655e (patch) | |
| tree | 6e57c4e13cf07486d4a02a3652bf84a9889f97a6 /modules/home-manager/emacs/config/lisp/qalc.el | |
| parent | 008b591a0a5942ae42f4c07a5abbee4dbd2d0743 (diff) | |
| download | nixos-configuration-cc47c443a3f86aa66d2719ee57c0e6e728ee655e.tar.gz nixos-configuration-cc47c443a3f86aa66d2719ee57c0e6e728ee655e.zip | |
feat: Included the emacs configdendritic
Some packages are built with nix and some are still built with emacs
Diffstat (limited to 'modules/home-manager/emacs/config/lisp/qalc.el')
| -rw-r--r-- | modules/home-manager/emacs/config/lisp/qalc.el | 64 |
1 files changed, 64 insertions, 0 deletions
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'. + +\\<qalc-mode-map>" + ;; 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) |
