From ec747395c64a1d6c64ce98dbe6b365f1578d2314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Thor=C3=A9n?= Date: Thu, 18 Feb 2021 21:49:49 +0100 Subject: [PATCH 1/6] Add support for parinfer-rust-mode (#1) This commit adds support for the module flag +rust, which will use parinfer-rust-mode instead of parinfer-mode. Parinfer-rust-mode makes use of an external library named parinfer-rust to do the heavy lifting. As such, --with-modules must be enabled. --- modules/editor/parinfer/README.org | 4 +- modules/editor/parinfer/config.el | 68 +++++++++++++++++++---------- modules/editor/parinfer/packages.el | 6 ++- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/modules/editor/parinfer/README.org b/modules/editor/parinfer/README.org index 807245f92..530df8764 100644 --- a/modules/editor/parinfer/README.org +++ b/modules/editor/parinfer/README.org @@ -17,7 +17,9 @@ https://raw.githubusercontent.com/DogLooksGood/parinfer-mode/a7c041454e05ec2b883 More information can be found about it [[https://shaunlebron.github.io/parinfer/][in the project's documentation]]. ** Module Flags -This module provides no flags. ++ =+rust= Use [[github:justinbarclay/parinfer-rust-mode][parinfer-rust-mode]] instead of the now deprecated [[github:DogLooksGood/parinfer-mode][parinfer-mode]]. + This depends on Emacs being compiled with the option `--with-modules`. The + pre-built library is only available for Linux, Windows and MacOS. ** Packages + [[https://github.com/DogLooksGood/parinfer-mode][parinfer]] diff --git a/modules/editor/parinfer/config.el b/modules/editor/parinfer/config.el index 912dfff39..92c0eb90a 100644 --- a/modules/editor/parinfer/config.el +++ b/modules/editor/parinfer/config.el @@ -1,24 +1,48 @@ ;;; editor/parinfer/config.el -*- lexical-binding: t; -*- -(use-package! parinfer - :hook ((emacs-lisp-mode - clojure-mode - scheme-mode - lisp-mode - racket-mode - hy-mode) . parinfer-mode) - :init - (setq parinfer-extensions - '(defaults - pretty-parens - smart-tab - smart-yank)) - (when (featurep! :editor evil +everywhere) - (push 'evil parinfer-extensions)) - :config - (map! :map parinfer-mode-map - "\"" nil ; smartparens handles this - :i "" #'parinfer-smart-tab:dwim-right-or-complete - :i "" #'parinfer-smart-tab:dwim-left - :localleader - :desc "Toggle parinfer-mode" "m" #'parinfer-toggle-mode)) +(if (not (featurep! +rust)) + (use-package! parinfer + :hook ((emacs-lisp-mode + clojure-mode + scheme-mode + lisp-mode + racket-mode + hy-mode) . parinfer-mode) + :init + (setq parinfer-extensions + '(defaults + pretty-parens + smart-tab + smart-yank)) + (when (featurep! :editor evil +everywhere) + (push 'evil parinfer-extensions)) + :config + (map! :map parinfer-mode-map + "\"" nil ; smartparens handles this + :i "" #'parinfer-smart-tab:dwim-right-or-complete + :i "" #'parinfer-smart-tab:dwim-left + :localleader + :desc "Toggle parinfer-mode" "m" #'parinfer-toggle-mode)) + (defvar parinfer-rust--doom-lib-name (cond ((eq system-type 'darwin) + "parinfer-rust-darwin.so") + ((eq system-type 'gnu/linux) + "parinfer-rust-linux.so") + ((eq system-type 'windows-nt) + "parinfer-rust-windows.dll"))) + (use-package! parinfer-rust-mode + :hook ((emacs-lisp-mode + clojure-mode + scheme-mode + lisp-mode + racket-mode + hy-mode) . parinfer-rust-mode) + :init + (setq! parinfer-rust-library (concat user-emacs-directory + ".local/etc/parinfer-rust/" + parinfer-rust--doom-lib-name)) + :config + (map! :map parinfer-rust-mode-map + :localleader + :desc "Switch parinfer-rust-mode" "m" #'parinfer-rust-switch-mode + :desc "Temporarily disable parinfer-rust-mode" "M" + #'parinfer-rust-switch-mode))) diff --git a/modules/editor/parinfer/packages.el b/modules/editor/parinfer/packages.el index 7b64e035b..c8bb373f2 100644 --- a/modules/editor/parinfer/packages.el +++ b/modules/editor/parinfer/packages.el @@ -1,7 +1,7 @@ ;; -*- no-byte-compile: t; -*- ;;; editor/parinfer/packages.el -(when (featurep! :editor evil) +(when (and (not (featurep! +rust)) (featurep! :editor evil)) ;; Parinfer uses `evil-define-key' without loading evil, so if evil is ;; installed *after* parinfer, parinfer will throw up void-function errors. ;; because evil-define-key (a macro) wasn't expanded at compile-time. So we @@ -11,4 +11,6 @@ ;; separate session: (autoload 'evil-define-key "evil-core" nil nil 'macro)) -(package! parinfer :pin "8659c99a9475ee34af683fdf8f272728c6bebb3a") +(if (featurep! +rust) + (package! parinfer-rust-mode :pin "c825606e6aca4a2ed18c0af321df5f36a3c8c774") + (package! parinfer :pin "8659c99a9475ee34af683fdf8f272728c6bebb3a")) From 4ff23752f2eaf520b12bd1fc1006af73cfe5a356 Mon Sep 17 00:00:00 2001 From: Johan Thoren Date: Sat, 27 Feb 2021 21:01:19 +0100 Subject: [PATCH 2/6] Update parinfer module to comply with review. Also add support for BSD systems. Signed-off-by: Johan Thoren --- modules/editor/parinfer/config.el | 87 +++++++++++++++-------------- modules/editor/parinfer/doctor.el | 11 ++++ modules/editor/parinfer/packages.el | 4 +- 3 files changed, 59 insertions(+), 43 deletions(-) create mode 100644 modules/editor/parinfer/doctor.el diff --git a/modules/editor/parinfer/config.el b/modules/editor/parinfer/config.el index 92c0eb90a..e13f31e14 100644 --- a/modules/editor/parinfer/config.el +++ b/modules/editor/parinfer/config.el @@ -1,48 +1,51 @@ ;;; editor/parinfer/config.el -*- lexical-binding: t; -*- -(if (not (featurep! +rust)) - (use-package! parinfer - :hook ((emacs-lisp-mode - clojure-mode - scheme-mode - lisp-mode - racket-mode - hy-mode) . parinfer-mode) - :init - (setq parinfer-extensions - '(defaults - pretty-parens - smart-tab - smart-yank)) - (when (featurep! :editor evil +everywhere) - (push 'evil parinfer-extensions)) - :config - (map! :map parinfer-mode-map - "\"" nil ; smartparens handles this - :i "" #'parinfer-smart-tab:dwim-right-or-complete - :i "" #'parinfer-smart-tab:dwim-left - :localleader - :desc "Toggle parinfer-mode" "m" #'parinfer-toggle-mode)) - (defvar parinfer-rust--doom-lib-name (cond ((eq system-type 'darwin) - "parinfer-rust-darwin.so") - ((eq system-type 'gnu/linux) - "parinfer-rust-linux.so") - ((eq system-type 'windows-nt) - "parinfer-rust-windows.dll"))) - (use-package! parinfer-rust-mode - :hook ((emacs-lisp-mode +(use-package! parinfer + :unless (featurep! +rust) + :hook ((emacs-lisp-mode clojure-mode scheme-mode lisp-mode racket-mode - hy-mode) . parinfer-rust-mode) - :init - (setq! parinfer-rust-library (concat user-emacs-directory - ".local/etc/parinfer-rust/" - parinfer-rust--doom-lib-name)) - :config - (map! :map parinfer-rust-mode-map - :localleader - :desc "Switch parinfer-rust-mode" "m" #'parinfer-rust-switch-mode - :desc "Temporarily disable parinfer-rust-mode" "M" - #'parinfer-rust-switch-mode))) + hy-mode) . parinfer-mode) + :init + (setq parinfer-extensions + '(defaults + pretty-parens + smart-tab + smart-yank)) + (when (featurep! :editor evil +everywhere) + (push 'evil parinfer-extensions)) + :config + (map! :map parinfer-mode-map + "\"" nil ; smartparens handles this + :i "" #'parinfer-smart-tab:dwim-right-or-complete + :i "" #'parinfer-smart-tab:dwim-left + :localleader + "m" #'parinfer-toggle-mode)) +(use-package! parinfer-rust-mode + :when (featurep! +rust) + :when (bound-and-true-p module-file-suffix) + :hook ((emacs-lisp-mode + clojure-mode + scheme-mode + lisp-mode + racket-mode + hy-mode) . parinfer-rust-mode) + :init + (setq! parinfer-rust-library + (concat user-emacs-directory + ".local/etc/parinfer-rust/" + (cond ((eq system-type 'darwin) "parinfer-rust-darwin.so") + ((eq system-type 'gnu/linux) "parinfer-rust-linux.so") + ((eq system-type 'windows-nt) "parinfer-rust-windows.dll") + ((eq system-type 'berkeley-unix "libparinfer_rust.so")))) + parinfer-rust-auto-download + (if (eq system-type 'berkeley-unix) + nil + t)) + :config + (map! :map parinfer-rust-mode-map + :localleader + "m" #'parinfer-rust-switch-mode + "M" #'parinfer-rust-toggle-disable)) diff --git a/modules/editor/parinfer/doctor.el b/modules/editor/parinfer/doctor.el new file mode 100644 index 000000000..4cf942123 --- /dev/null +++ b/modules/editor/parinfer/doctor.el @@ -0,0 +1,11 @@ +;;; editor/parinfer/doctor.el -*- lexical-binding: t; -*- + +(when (featurep! +rust) + (unless (fboundp 'module-load) + (warn! "Your emacs wasn't built with dynamic modules support. `parinfer-rust-mode' won't work")) + (when (and (eq system-type 'berkeley-unix) + (not (file-readable-p + (concat user-emacs-directory ".local/etc/parinfer-rust/libparinfer_rust.so")))) + (warn! (concat "Could not read " user-emacs-directory + ".local/etc/parinfer-rust/libparinfer_rust.so. " + "`parinfer-rust-mode' won't work")))) diff --git a/modules/editor/parinfer/packages.el b/modules/editor/parinfer/packages.el index c8bb373f2..437b9dbe3 100644 --- a/modules/editor/parinfer/packages.el +++ b/modules/editor/parinfer/packages.el @@ -13,4 +13,6 @@ (if (featurep! +rust) (package! parinfer-rust-mode :pin "c825606e6aca4a2ed18c0af321df5f36a3c8c774") - (package! parinfer :pin "8659c99a9475ee34af683fdf8f272728c6bebb3a")) + (package! parinfer + :recipe (:host github :repo "emacsattic/parinfer") + :pin "8659c99a9475ee34af683fdf8f272728c6bebb3a")) From 8262e1b552d71f4a1b650976571e3c64e5cc73de Mon Sep 17 00:00:00 2001 From: Johan Thoren Date: Sat, 27 Feb 2021 21:03:16 +0100 Subject: [PATCH 3/6] Fix incorrect indentation. Signed-off-by: Johan Thoren --- modules/editor/parinfer/config.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/editor/parinfer/config.el b/modules/editor/parinfer/config.el index e13f31e14..d88bca36e 100644 --- a/modules/editor/parinfer/config.el +++ b/modules/editor/parinfer/config.el @@ -3,11 +3,11 @@ (use-package! parinfer :unless (featurep! +rust) :hook ((emacs-lisp-mode - clojure-mode - scheme-mode - lisp-mode - racket-mode - hy-mode) . parinfer-mode) + clojure-mode + scheme-mode + lisp-mode + racket-mode + hy-mode) . parinfer-mode) :init (setq parinfer-extensions '(defaults From ca673a437c59a00dc06393e6edf07202843cade2 Mon Sep 17 00:00:00 2001 From: Johan Thoren Date: Sat, 27 Feb 2021 23:43:24 +0100 Subject: [PATCH 4/6] Move paren. Signed-off-by: Johan Thoren --- modules/editor/parinfer/config.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/editor/parinfer/config.el b/modules/editor/parinfer/config.el index d88bca36e..29592b518 100644 --- a/modules/editor/parinfer/config.el +++ b/modules/editor/parinfer/config.el @@ -39,7 +39,7 @@ (cond ((eq system-type 'darwin) "parinfer-rust-darwin.so") ((eq system-type 'gnu/linux) "parinfer-rust-linux.so") ((eq system-type 'windows-nt) "parinfer-rust-windows.dll") - ((eq system-type 'berkeley-unix "libparinfer_rust.so")))) + ((eq system-type 'berkeley-unix) "libparinfer_rust.so"))) parinfer-rust-auto-download (if (eq system-type 'berkeley-unix) nil From 1a3c3ddf34c301c299306279afa3cd13fc12fe78 Mon Sep 17 00:00:00 2001 From: Johan Thoren Date: Sun, 28 Feb 2021 00:18:00 +0100 Subject: [PATCH 5/6] Use `setq` instead of `setq!`. Signed-off-by: Johan Thoren --- modules/editor/parinfer/config.el | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/modules/editor/parinfer/config.el b/modules/editor/parinfer/config.el index 29592b518..6d95dd96f 100644 --- a/modules/editor/parinfer/config.el +++ b/modules/editor/parinfer/config.el @@ -33,17 +33,14 @@ racket-mode hy-mode) . parinfer-rust-mode) :init - (setq! parinfer-rust-library - (concat user-emacs-directory - ".local/etc/parinfer-rust/" - (cond ((eq system-type 'darwin) "parinfer-rust-darwin.so") - ((eq system-type 'gnu/linux) "parinfer-rust-linux.so") - ((eq system-type 'windows-nt) "parinfer-rust-windows.dll") - ((eq system-type 'berkeley-unix) "libparinfer_rust.so"))) - parinfer-rust-auto-download - (if (eq system-type 'berkeley-unix) - nil - t)) + (setq parinfer-rust-library + (concat user-emacs-directory + ".local/etc/parinfer-rust/" + (cond ((eq system-type 'darwin) "parinfer-rust-darwin.so") + ((eq system-type 'gnu/linux) "parinfer-rust-linux.so") + ((eq system-type 'windows-nt) "parinfer-rust-windows.dll") + ((eq system-type 'berkeley-unix) "libparinfer_rust.so")))) + (setq parinfer-rust-auto-download (if (eq system-type 'berkeley-unix) nil t)) :config (map! :map parinfer-rust-mode-map :localleader From 96ba4b0b38f31ed9fdc40e7bcde93aacf9d50c8d Mon Sep 17 00:00:00 2001 From: Johan Thoren Date: Sun, 28 Feb 2021 00:19:12 +0100 Subject: [PATCH 6/6] Use easier to read line break. Signed-off-by: Johan Thoren --- modules/editor/parinfer/doctor.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/editor/parinfer/doctor.el b/modules/editor/parinfer/doctor.el index 4cf942123..41528d6ea 100644 --- a/modules/editor/parinfer/doctor.el +++ b/modules/editor/parinfer/doctor.el @@ -4,8 +4,8 @@ (unless (fboundp 'module-load) (warn! "Your emacs wasn't built with dynamic modules support. `parinfer-rust-mode' won't work")) (when (and (eq system-type 'berkeley-unix) - (not (file-readable-p - (concat user-emacs-directory ".local/etc/parinfer-rust/libparinfer_rust.so")))) + (not (file-readable-p (concat user-emacs-directory + ".local/etc/parinfer-rust/libparinfer_rust.so")))) (warn! (concat "Could not read " user-emacs-directory ".local/etc/parinfer-rust/libparinfer_rust.so. " "`parinfer-rust-mode' won't work"))))