diff --git a/.config.d/05-basic.el b/.config.d/05-basic.el index 9dbde66..6e82bd8 100644 --- a/.config.d/05-basic.el +++ b/.config.d/05-basic.el @@ -53,7 +53,7 @@ :straight (hbdh :type git :host github :repo "zzhjerry/hbdh-mode") :config (hbdh-mode)) -(defun my/hbdh-highlight-line () +(defun my-hbdh-highlight-line () "Activate hbdh, dim text outside of current line" (interactive) (let ((point-beginning (line-beginning-position)) @@ -66,7 +66,7 @@ (setq hbdh-mode-map (make-sparse-keymap)) (define-key hbdh-mode-map "a" 'hbdh-activate-on-region) (define-key hbdh-mode-map "d" 'hbdh-deactivate) -(define-key hbdh-mode-map "l" 'my/hbdh-highlight-line) +(define-key hbdh-mode-map "l" 'my-hbdh-highlight-line) (global-set-key "\C-ch" hbdh-mode-map) @@ -118,4 +118,25 @@ (unless (memq 'vterm features) (load "vterm" nil t)) +;; +(add-to-list 'load-path (expand-file-name (concat minimal-emacs-user-directory "load"))) + +(register-input-method + "cyrillic-workman" "Russian" 'quail-use-package + "RUW@" "Russian (ЙЦУКЕН) input method simulating Workman keyboard" + "cyrillic-workman-input-method") + +;; Reverse-IM creates additional bindings that allow usage of different input +;; methods without changing the keyboard layout (most of the time ,for example: +;; keybinds on russian layout will work with this package). +(use-package reverse-im + :ensure t + :defer nil) + +(setq reverse-im-char-fold t) ; use lax matching +(setq reverse-im-read-char-advice-function #'reverse-im-read-char-include) +(setq reverse-im-input-methods '("cyrillic-workman")) ; translate these methods + +(reverse-im-mode t) + ;;; 05-basic.el ends here diff --git a/.config.d/15-lsp.el b/.config.d/15-lsp.el index 2340669..94cc3a2 100644 --- a/.config.d/15-lsp.el +++ b/.config.d/15-lsp.el @@ -1,8 +1,8 @@ ;;; 15-lsp.el --- Setup LSP -*- no-byte-compile: t; lexical-binding: t; -*- -;;; Description: +;;; Commentary: ;; Despite the name, this file not only sets up LSP integration, but -;; also native emacs modes for various programming lanuguages, such as +;; also native Emacs modes for various programming lanuguages, such as ;; Prolog, that do not use LSP. ;;; Code: @@ -28,13 +28,16 @@ (setq jsonrpc-event-hook nil)) ;; This function raises the window to the front using KDE KWin. -(defun my/raise-window () +(defun my-raise-window () + "Raises the window to the front using KDE KWin. + +Won't work if the script is not there." (call-process-shell-command "~/wayland-window -f emacs &" nil 0)) ;; Usually, when I open a file with emacsclient and the frame already exists, I ;; want it to be raised to the top. Unfortunately, that does not happen by ;; default. Here is my solution. -(add-hook 'server-visit-hook #'my/raise-window) +(add-hook 'server-visit-hook #'my-raise-window) ;; This package provides syntax highlighting for gdscript. (use-package gdscript-mode @@ -77,12 +80,24 @@ :ensure t :defer t :commands (prolog-mode) - :init - (setq ediprolog-program "systemd-run") - (setq ediprolog-program-switches '("--user" "--scope" "-p" "MemoryMax=2G" "-p" "MemoryHigh=1.9G" "scryer-prolog"))) + :config + (my-ediprolog-select-system "swi-prolog")) + +(defun ediprolog-set-term-type (orig &rest args) + "Advice to set the TERM env var to dumb for the function call. + +Originally created for scryer prolog, as either it itself or systemd-run +used to constrain its resources assumed that the terminal supports +escape codes (it does not in this case), so this was used as an +\":around\" advice on 'ediprolog-run-prolog', to clearly indicate that +control codes are not supported." + (let ((process-environment process-environment)) + (setenv "TERM" "dumb") + (apply orig args))) (with-eval-after-load "prolog" - (bind-key "C-c C-e" #'ediprolog-dwim prolog-mode-map)) + (bind-key "C-c C-e" #'ediprolog-dwim prolog-mode-map) + (advice-add 'ediprolog-run-prolog :around #'ediprolog-set-term-type)) (add-to-list 'auto-mode-alist '("\\.plt?\\'" . prolog-mode)) (add-to-list 'auto-mode-alist '("\\.axaml?\\'" . nxml-mode)) @@ -126,17 +141,17 @@ ;; Add other languages as needed (indent-bars-treesit-scope '((python function_definition class_definition for_statement if_statement with_statement while_statement) - (rust trait_item impl_item - macro_definition macro_invocation - struct_item enum_item mod_item - const_item let_declaration - function_item for_expression - if_expression loop_expression - while_expression match_expression - match_arm call_expression - token_tree token_tree_pattern + (rust trait_item impl_item + macro_definition macro_invocation + struct_item enum_item mod_item + const_item let_declaration + function_item for_expression + if_expression loop_expression + while_expression match_expression + match_arm call_expression + token_tree token_tree_pattern token_repetition))) (indent-bars-treesit-wrap '((rust arguments parameters))) :hook ((python-base-mode yaml-mode rust-mode) . indent-bars-mode)) -;;; 15-lsp.el end here +;;; 15-lsp.el ends here diff --git a/.config.d/99-misc.el b/.config.d/99-misc.el index 2710809..36041d8 100644 --- a/.config.d/99-misc.el +++ b/.config.d/99-misc.el @@ -7,25 +7,25 @@ ;;; Code: -(defun my/resize-margins-to-fill () +(defun my-resize-margins-to-fill () "Set the current buffer margins so that its width is equal to the fill column." (interactive) (let ((margin-size (/ (- (frame-width) fill-column) 2))) (set-window-margins nil margin-size margin-size))) -(defun my/reset-margins () +(defun my-reset-margins () "Removes margins from the current buffer." (interactive) (set-window-margins nil nil nil)) -(defun my/insert-buffer-name () +(defun my-insert-buffer-name () "Inserts the name of the current buffer at point." (interactive) (let ((name (buffer-name))) (insert name))) -(defun my/create-org-fc-word-card () +(defun my-create-org-fc-word-card () "Inserts and initialzes an org-fc double card with a word and its translation at point." (interactive) @@ -37,13 +37,13 @@ translation at point." (previous-line) (org-fc-type-double-init))) -(keymap-set org-mode-map "C-c C-n" 'my/create-org-fc-word-card) +(keymap-set org-mode-map "C-c C-n" 'my-create-org-fc-word-card) (setq margins-map (make-sparse-keymap)) -(keymap-set margins-map "f" 'my/resize-margins-to-fill) -(keymap-set margins-map "r" 'my/reset-margins) +(keymap-set margins-map "f" 'my-resize-margins-to-fill) +(keymap-set margins-map "r" 'my-reset-margins) (keymap-set mode-specific-map "C-m" margins-map) -(keymap-set mode-specific-map "b" 'my/insert-buffer-name) +(keymap-set mode-specific-map "b" 'my-insert-buffer-name) ;;; 99-misc.el ends here diff --git a/.config.d/99-my-ediprolog.el b/.config.d/99-my-ediprolog.el index b59512a..d895ad0 100644 --- a/.config.d/99-my-ediprolog.el +++ b/.config.d/99-my-ediprolog.el @@ -1,7 +1,14 @@ ;;; 99-my-ediprolog.el --- ediprolog extras -*- no-byte-compile: t; lexical-binding: t; -*- -(defun my/ediprolog-run-in-own-buffer () - "Copy this query to another buffer and run it there" + +;;; Commentary: +;; ediprolog is a very minimalist package, and I find myself needing to code +;; some functionality myself. Ergo, this file. + +;;; Code: + +(defun my-ediprolog-run-in-own-buffer () + "Copy this query to another buffer and run it there." (interactive) ;; This is the same logic ediprolog uses to check if the point is on query. (when (and (not (and transient-mark-mode mark-active)) @@ -29,4 +36,51 @@ (ediprolog-dwim)))) -;; 99-my-ediprolog.el ends here +(defun my-ediprolog-delete-next-comments () + "Delete all commented lines after point (excluding the line under point). +Will continue until a line without a comment is encountered. See also +'ediprolog-dwim'." + (interactive) + (save-excursion + (beginning-of-line) + (next-line) + (while (looking-at "[ ]*%") + (delete-line)))) + +(defun my-ediprolog-return-to-closest-query () + "Tries to set point to closest query (starts with ?-) preceding it." + (interactive) + (re-search-backward "\\([\t ]*%*[\t ]*[:?]- *\\)" nil t)) + +(defcustom my-ediprolog-system-types + '(("scryer-prolog" . (scryer . ("systemd-run" "--user" "--scope" "-p" "MemoryMax=2G" "-p" "MemoryHigh=1.9G" "scryer-prolog"))) + ("swi-prolog" . (swi . ("swipl")))) + "An alist of prolog systems and their respective run commands. + +This has the form of form (NAME . TYPE . COMMAND). NAME is the display +name that user will be presented with, TYPE is one of swi or scryer, for +the two supported prolog systems respectively. COMMAND is a list, where +the first element is the command and the rest are arguments. See +'my-ediprolog-select-system'" + :type '(alist + :key-type string + :value-type (cons (choice (const :tag "Scryer Prolog" :value scryer) + (const :tag "SWI Prolog" :value swi)) + (repeat string)))) + +(defun my-ediprolog-select-system (&optional system) + "Prompts the user to select a prolog SYSTEM and configures ediprolog to use it. + +The prolog systems are defined in 'my-ediprolog-system-types'." + (interactive (list (completing-read "Select system:" my-ediprolog-system-types))) + + (let ((pair (alist-get system my-ediprolog-system-types nil nil #'equal))) + (setq ediprolog-system (car pair)) + (setq ediprolog-program (cadr pair)) + (setq ediprolog-program-switches (cddr pair)))) + +(with-eval-after-load 'prolog + (keymap-set prolog-mode-map "C-c C-d" #'my-ediprolog-delete-next-comments) + (keymap-set prolog-mode-map "C-c C-b" #'my-ediprolog-return-to-closest-query)) + +;;; 99-my-ediprolog.el ends here diff --git a/custom.el b/custom.el index e8a0fcb..223d90f 100644 --- a/custom.el +++ b/custom.el @@ -3,7 +3,7 @@ ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. - '(auth-source-save-behavior nil)) + ) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful.