From 4ecd616cd8f60640d6b0be2ffc3d762e88099bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Tue, 16 Aug 2022 08:13:55 +0100 Subject: [PATCH 01/85] refactor(format): replace with apheleia Initial refactor of format module to replace format-all with apheleia --- modules/editor/format/autoload/format.el | 319 ++++----------------- modules/editor/format/autoload/settings.el | 161 ++--------- modules/editor/format/config.el | 89 ++---- modules/editor/format/packages.el | 3 +- modules/editor/format/test/test-format.el | 103 ------- modules/lang/ocaml/config.el | 2 - modules/lang/php/config.el | 1 - modules/lang/sh/config.el | 15 +- modules/lang/web/+html.el | 18 +- 9 files changed, 126 insertions(+), 585 deletions(-) delete mode 100644 modules/editor/format/test/test-format.el diff --git a/modules/editor/format/autoload/format.el b/modules/editor/format/autoload/format.el index b06290da9..6f5ee252b 100644 --- a/modules/editor/format/autoload/format.el +++ b/modules/editor/format/autoload/format.el @@ -1,276 +1,85 @@ ;;; editor/format/autoload.el -*- lexical-binding: t; -*- -(defvar +format-region-p nil - "Is non-nil if currently reformatting a selected region, rather than the whole -buffer.") - -;;;###autoload -(autoload 'format-all--probe "format-all") - -(defun +format--delete-whole-line (&optional arg) - "Delete the current line without putting it in the `kill-ring'. -Derived from function `kill-whole-line'. ARG is defined as for that -function. - -Stolen shamelessly from go-mode" - (setq arg (or arg 1)) - (if (and (> arg 0) - (eobp) - (save-excursion (forward-visible-line 0) (eobp))) - (signal 'end-of-buffer nil)) - (if (and (< arg 0) - (bobp) - (save-excursion (end-of-visible-line) (bobp))) - (signal 'beginning-of-buffer nil)) - (cond ((zerop arg) - (delete-region (progn (forward-visible-line 0) (point)) - (progn (end-of-visible-line) (point)))) - ((< arg 0) - (delete-region (progn (end-of-visible-line) (point)) - (progn (forward-visible-line (1+ arg)) - (unless (bobp) - (backward-char)) - (point)))) - ((delete-region (progn (forward-visible-line 0) (point)) - (progn (forward-visible-line arg) (point)))))) - -;;;###autoload -(defun +format--apply-rcs-patch (patch-buffer) - "Apply an RCS-formatted diff from PATCH-BUFFER to the current buffer. - -Stolen shamelessly from go-mode" - (let ((target-buffer (current-buffer)) - ;; Relative offset between buffer line numbers and line numbers - ;; in patch. - ;; - ;; Line numbers in the patch are based on the source file, so - ;; we have to keep an offset when making changes to the - ;; buffer. - ;; - ;; Appending lines decrements the offset (possibly making it - ;; negative), deleting lines increments it. This order - ;; simplifies the forward-line invocations. - (line-offset 0) - (column (current-column))) - (save-excursion - (with-current-buffer patch-buffer - (goto-char (point-min)) - (while (not (eobp)) - (unless (looking-at "^\\([ad]\\)\\([0-9]+\\) \\([0-9]+\\)") - (error "Invalid rcs patch or internal error in +format--apply-rcs-patch")) - (forward-line) - (let ((action (match-string 1)) - (from (string-to-number (match-string 2))) - (len (string-to-number (match-string 3)))) - (cond - ((equal action "a") - (let ((start (point))) - (forward-line len) - (let ((text (buffer-substring start (point)))) - (with-current-buffer target-buffer - (cl-decf line-offset len) - (goto-char (point-min)) - (forward-line (- from len line-offset)) - (insert text))))) - ((equal action "d") - (with-current-buffer target-buffer - (goto-char (point-min)) - (forward-line (1- (- from line-offset))) - (cl-incf line-offset len) - (+format--delete-whole-line len))) - ((error "Invalid rcs patch or internal error in +format--apply-rcs-patch"))))))) - (move-to-column column))) - (defun +format--current-indentation () (save-excursion (goto-char (point-min)) (skip-chars-forward " \t\n") (current-indentation))) - -;; -;; Public library - -(defun +format-completing-read () - "TODO" - (require 'format-all) - (let* ((fmtlist (mapcar #'symbol-name (hash-table-keys format-all--format-table))) - (fmt (completing-read "Formatter: " fmtlist))) - (if fmt (intern fmt)))) - -;;;###autoload -(defun +format-probe-a (fn) - "Use `+format-with' instead, if it is set. -Prompts for a formatter if universal arg is set." - (cond ((or buffer-read-only (eq +format-with :none)) - (list nil nil)) - (current-prefix-arg - (list (or (+format-completing-read) - (user-error "Aborted")) - t)) - (+format-with - (list +format-with t)) - ((and +format-with-lsp - (bound-and-true-p lsp-managed-mode) - (lsp-feature? "textDocument/formatting")) - (list 'lsp nil)) - ((and +format-with-lsp - (bound-and-true-p eglot--managed-mode) - (eglot--server-capable :documentFormattingProvider)) - (list 'eglot nil)) - ((funcall fn)))) - -;;;###autoload -(defun +format-buffer-a (formatter mode-result) - "Advice that extends `format-all-buffer--with' to: - -1. Enable partial/region reformatting, while preserving leading indentation, -2. Applies changes via RCS patch, line by line, to protect buffer markers and - reduce cursor movement or window scrolling. - -See `+format/buffer' for the interactive version of this function, and -`+format-buffer-h' to use as a `before-save-hook' hook." - (cond - ((eq formatter 'lsp) - (call-interactively - (if +format-region-p #'lsp-format-region #'lsp-format-buffer))) - ((eq formatter 'eglot) - (call-interactively - (if +format-region-p #'eglot-format #'eglot-format-buffer))) - ((let ((f-function (gethash formatter format-all--format-table)) - (executable (format-all--formatter-executable formatter)) - (indent 0) - (old-line-number (line-number-at-pos)) - (old-column (current-column))) - (pcase-let* - ((`(,output ,errput) - ;; To reliably format regions, rather than the whole buffer, and - ;; `format-all' (and various formatting functions, like `gofmt') widen - ;; the buffer, we must copy the region first. - (let ((output (buffer-substring-no-properties (point-min) (point-max))) - (origin-buffer (or (buffer-base-buffer) (current-buffer))) - ;; Fixes #5133: some packages (like lsp-mode) can do a bunch - ;; of complicated stuff in these hooks. Better to not have to - ;; deal with any of them at all. - write-file-functions - before-save-hook - after-save-hook - kill-buffer-query-functions - kill-buffer-hook) - (with-temp-buffer - (with-silent-modifications - (insert output) - ;; Ensure this temp buffer seems as much like the origin - ;; buffer as possible, in case the formatter is an elisp - ;; function, like `gofmt'. - (cl-loop for (var . val) - in (cl-remove-if-not #'listp (buffer-local-variables origin-buffer)) - ;; Making enable-multibyte-characters buffer-local - ;; causes an error. - unless (eq var 'enable-multibyte-characters) - ;; Fixes #5133: don't deal with complicated hook - ;; functionality! This isn't a real buffer anyway. - unless (string-match-p (symbol-name var) "-\\(hook\\|functions\\)$") - ;; Using setq-local would quote var. - do (set (make-local-variable var) val)) - ;; Since we're piping a region of text to the formatter, remove - ;; any leading indentation to make it look like a file. - (setq indent (+format--current-indentation)) - (when (> indent 0) - (indent-rigidly (point-min) (point-max) (- indent))) - (funcall f-function executable mode-result))))) - (`,status - (cond ((null output) :error) - ((eq output t) :already-formatted) - (t :reformatted)))) - (unwind-protect - (when (eq status :reformatted) - (let ((tmpfile (make-temp-file "doom-format")) - (patchbuf (get-buffer-create " *doom format patch*")) - (coding-system-for-read coding-system-for-read) - (coding-system-for-write coding-system-for-write)) - (unless IS-WINDOWS - (setq coding-system-for-read 'utf-8 - coding-system-for-write 'utf-8)) - (unwind-protect - (progn - (with-current-buffer patchbuf - (erase-buffer)) - (with-temp-file tmpfile - (erase-buffer) - (insert output) - (when (> indent 0) - ;; restore indentation without affecting new - ;; indentation - (indent-rigidly (point-min) (point-max) - (max 0 (- indent (+format--current-indentation)))))) - (if (zerop (call-process-region (point-min) (point-max) "diff" nil patchbuf nil "-n" "-" tmpfile)) - (setq status :already-formatted) - (+format--apply-rcs-patch patchbuf) - (list output errput))) - (kill-buffer patchbuf) - (delete-file tmpfile)))) - (format-all--show-or-hide-errors errput) - (goto-char (point-min)) - (forward-line (1- old-line-number)) - (let ((line-length (- (point-at-eol) (point-at-bol)))) - (goto-char (+ (point) (min old-column line-length)))) - (run-hook-with-args 'format-all-after-format-functions formatter status) - (message (pcase status - (:error "Formatting error") - (:already-formatted "Already formatted") - (:reformatted (format "Reformatted with %s" formatter)))))))))) +(defun +format-region (start end &optional callback) + "Format from START to END with `apheleia'." + (when-let* ((command (apheleia--get-formatter-command + (if current-prefix-arg + 'prompt + 'interactive))) + (cur-buffer (current-buffer)) + (formatted-buffer (get-buffer-create " *apheleia-formatted*")) + (indent 0)) + (with-current-buffer formatted-buffer + (erase-buffer) + (unless IS-WINDOWS + (setq-local coding-system-for-read 'utf-8) + (setq-local coding-system-for-write 'utf-8)) + ;; Ensure this temp buffer seems as much like the origin buffer as + ;; possible, in case the formatter is an elisp function, like `gofmt'. + (cl-loop for (var . val) + in (cl-remove-if-not #'listp (buffer-local-variables origin-buffer)) + ;; Making enable-multibyte-characters buffer-local causes an + ;; error. + unless (eq var 'enable-multibyte-characters) + ;; Using setq-local would quote var. + do (set (make-local-variable var) val)) + ;; + (insert-buffer-substring-no-properties cur-buffer start end) + ;; Since we're piping a region of text to the formatter, remove any + ;; leading indentation to make it look like a file. + (setq indent (+format--current-indentation)) + (when (> indent 0) + (indent-rigidly (point-min) (point-max) (- indent))) + ;; + (apheleia-format-buffer + command + (lambda () + (with-current-buffer formatted-buffer + (when (> indent 0) + ;; restore indentation without affecting new + ;; indentation + (indent-rigidly (point-min) (point-max) + (max 0 (- indent (+format--current-indentation)))))) + (with-current-buffer cur-buffer + (delete-region start end) + (insert-buffer-substring-no-properties formatted-buffer) + (when callback (funcall callback)) + (kill-buffer formatted-buffer))))))) ;; ;;; Commands -(defun +format--org-region (beg end) - "Reformat the region within BEG and END. -If nil, BEG and/or END will default to the boundaries of the src block at point." - (let ((element (org-element-at-point))) - (save-excursion - (let* ((block-beg (save-excursion - (goto-char (org-babel-where-is-src-block-head element)) - (line-beginning-position 2))) - (block-end (save-excursion - (goto-char (org-element-property :end element)) - (skip-chars-backward " \t\n") - (line-beginning-position))) - (beg (if beg (max beg block-beg) block-beg)) - (end (if end (min end block-end) block-end)) - (lang (org-element-property :language element)) - (major-mode (org-src-get-lang-mode lang))) - (if (eq major-mode 'org-mode) - (user-error "Cannot reformat an org src block in org-mode") - (+format/region beg end)))))) - -(defun +format--buffer () - (if (and (eq major-mode 'org-mode) - (org-in-src-block-p t)) - (+format--org-region (point-min) (point-max)) - (if (called-interactively-p 'any) - (format-all-buffer) - (ignore-errors (format-all-buffer))))) - ;;;###autoload -(defun +format/buffer () +(defun +format/buffer (&optional arg) "Reformat the current buffer using LSP or `format-all-buffer'." - (interactive) - (+format--buffer)) + (interactive "P") + (call-interactively + (if (and +format-with-lsp + (bound-and-true-p lsp-mode) + (lsp-feature? "textDocument/formatting")) + #'lsp-format-buffer + #'apheleia-format-buffer))) ;;;###autoload -(defun +format/region (beg end) +(defun +format/region (beg end &optional arg) "Runs the active formatter on the lines within BEG and END. WARNING: this may not work everywhere. It will throw errors if the region contains a syntax error in isolation. It is mostly useful for formatting snippets or single lines." (interactive "rP") - (let ((+format-region-p t)) - (save-restriction - (narrow-to-region beg end) - (+format--buffer)))) + (if (and +format-with-lsp + (bound-and-true-p lsp-mode) + (lsp-feature? "textDocument/rangeFormatting")) + (call-interactively #'lsp-format-region) + (+format-region beg end))) ;;;###autoload (defun +format/region-or-buffer () @@ -281,13 +90,3 @@ is selected)." (if (doom-region-active-p) #'+format/region #'+format/buffer))) - - -;; -;; Hooks - -;;;###autoload -(defalias '+format-buffer-h #'+format/buffer - "Format the source code in the current buffer with minimal feedback. - -Meant for `before-save-hook'.") diff --git a/modules/editor/format/autoload/settings.el b/modules/editor/format/autoload/settings.el index 0261c175f..0406facdb 100644 --- a/modules/editor/format/autoload/settings.el +++ b/modules/editor/format/autoload/settings.el @@ -1,97 +1,11 @@ ;;; editor/format/autoload/settings.el -*- lexical-binding: t; -*- -;; This must be redefined here because `format-all' only makes it available at -;; compile time. -(defconst +format-system-type - (cl-case system-type - (windows-nt 'windows) - (cygwin 'windows) - (darwin 'macos) - (gnu/linux 'linux) - (berkeley-unix - (save-match-data - (let ((case-fold-search t)) - (cond ((string-match "freebsd" system-configuration) 'freebsd) - ((string-match "openbsd" system-configuration) 'openbsd) - ((string-match "netbsd" system-configuration) 'netbsd)))))) - "Current operating system according to the format-all package.") - -(defun +format--resolve-system (choices) - "Get first choice matching `format-all-system-type' from CHOICES." - (cl-loop for choice in choices - if (atom choice) return choice - else if (eql +format-system-type (car choice)) - return (cadr choice))) - - -(defun +format--make-command (formatter &rest _) - `(format-all--buffer-thunk - (lambda (input) - (with-silent-modifications - (setq buffer-file-name ,(buffer-file-name (buffer-base-buffer)) - default-directory ,default-directory) - (delay-mode-hooks (funcall ',major-mode)) - (insert input) - (condition-case e - (progn - (doom-log "formatter (commandp) %s" #',formatter) - (call-interactively #',formatter) - (list nil "")) - (error (list t (error-message-string e)))))))) - -(defun +format--make-function (formatter &rest _) - `(progn - (doom-log "formatter (functionp) %s" #',formatter) - (format-all--buffer-thunk #',formatter))) - -(defun +format--make-shell-command (command ok-statuses error-regexp) - (+format--make-shell-command-list (split-string command " " t) - ok-statuses error-regexp)) - -(defun +format--make-shell-command-list (command-list ok-statuses error-regexp) - `(let (args) - (dolist (arg ',command-list) - (cond ((stringp arg) - (push arg args)) - ((listp arg) - (catch 'skip - (let (subargs this) - (while (setq this (pop arg)) - (cond ((not (stringp (car arg))) - (let ((val (eval (pop arg) t))) - (unless val (throw 'skip nil)) - (push (format this val) subargs))) - ((stringp this) - (push this subargs)))) - (setq args (append subargs args))))))) - (doom-log "formatter (arglist) %s" args) - (if ,(and (or ok-statuses error-regexp) t) - (apply #'format-all--buffer-hard - ',ok-statuses ,error-regexp nil - (reverse args)) - (apply #'format-all--buffer-easy (reverse args))))) - -(cl-defun +format--set (name &key function modes unset) - (declare (indent defun)) - (when (and unset (not (gethash name format-all--format-table))) - (error "'%s' formatter does not exist to be unset" name)) - (puthash name function format-all--format-table) - (dolist (mode (ensure-list modes)) - (cl-destructuring-bind (m &optional probe) - (ensure-list mode) - (if unset - (puthash m (assq-delete-all name (gethash key format-all-mode-table)) - format-all-mode-table) - (format-all--pushhash - m (cons name (if probe `(lambda () ,probe))) - format-all--mode-table))))) - ;;;###autodef (cl-defun set-formatter! - (name formatter &key modes filter ok-statuses error-regexp) + (name &rest args &key modes filter &allow-other-keys) "Define (or modify) a formatter named NAME. -Supported keywords: :modes :filter :ok-statuses :error-regexp +Supported keywords: :modes :filter NAME is a symbol that identifies this formatter. @@ -99,7 +13,7 @@ FORMATTER can be a symbol referring to another formatter, a function, string or nested list. If a function, it should be a formatter function that - `format-all--buffer-thunk' will accept. + `apheleia--run-formatter-function' will accept. If a string, it is assumed to be a shell command that the buffer's text will be piped to (through stdin). If a list, it should represent a shell command as a list of arguments. Each @@ -107,6 +21,9 @@ nested list. string and ARG is both a predicate and argument for STRING. If ARG is nil, STRING will be omitted from the vector. +For more information on how to structure the list to be +compatible, see `apheleia--run-formatter-function'. + MODES is a major mode, a list thereof, or a list of two-element sublists with the structure: (MAJOR-MODE FORM). FORM is evaluated when the buffer is formatted and its return value serves two purposes: @@ -116,27 +33,12 @@ and its return value serves two purposes: 2. It's return value is made available to FORMATTER if it is a function or list of shell arguments via the `mode-result' variable. -FILTER is a function that takes three arguments: the formatted output, any error -output and the position of the first change. This function must return these -three after making whatever changes you like to them. This might be useful if -the output contains ANSI color codes that need to be stripped out (as is the -case with elm-format). - -OK-STATUSES and ERROR-REGEXP are ignored if FORMATTER is not a shell command. - -OK-STATUSES is a list of integer exit codes that should be treated as success -codes. However, if ERROR-REGEXP is given, and the program's stderr contains that -regexp, then the formatting is considered failed even if the exit status is in -OK-STATUSES. - Basic examples: - (set-formatter! 'asmfmt \"asmfmt\" :modes '(asm-mode nasm-mode)) (set-formatter! 'black \"black -q -\") (set-formatter! 'html-tidy \"tidy -q -indent\" :modes '(html-mode web-mode)) Advanced examples: - (set-formatter! 'clang-format '(\"clang-format\" @@ -154,9 +56,7 @@ Advanced examples: :modes '(html-mode (web-mode (and (equal \"none\" web-mode-engine) - (car (member web-mode-content-type '(\"xml\" \"html\")))))) - :ok-statuses '(0 1) - :executable \"tidy\") + (car (member web-mode-content-type '(\"xml\" \"html\"))))))) (set-formatter! 'html-tidy ; overwrite predefined html-tidy formatter '(\"tidy\" \"-q\" \"-indent\" @@ -165,39 +65,22 @@ Advanced examples: \"--show-body-only\" \"auto\" (\"--indent-spaces\" \"%d\" tab-width) (\"--indent-with-tabs\" \"%s\" (if indent-tabs-mode \"yes\" \"no\")) - (\"-xml\" (memq major-mode '(nxml-mode xml-mode)))) - :ok-statuses '(0 1))) + (\"-xml\" (memq major-mode '(nxml-mode xml-mode))))) (set-formatter! 'elm-format - \"elm-format --yes --stdin\" - :filter - (lambda (output errput first-diff) - (list output - (format-all--remove-ansi-color errput) - first-diff)))" + \"elm-format --yes --stdin\") +" (declare (indent defun)) (cl-check-type name symbol) - (after! format-all - (if (null formatter) - (+format--set name - :unset t - :modes modes) - (let ((fn (funcall (cond ((stringp formatter) - #'+format--make-shell-command) - ((listp formatter) - #'+format--make-shell-command-list) - ((and (commandp formatter) - (not (stringp formatter))) - #'+format--make-command) - ((functionp formatter) - #'+format--make-function)) - formatter - ok-statuses - error-regexp))) - (cl-check-type filter (or function null)) - (+format--set name - :function - `(lambda (executable mode-result) - ,(if filter `(apply #',filter ,fn) fn)) - :modes modes) - name)))) + (after! apheleia + (if (null args) + (progn + (setq apheleia-formatters + (assq-delete-all name apheleia-formatters)) + (while (rassoc name apheleia-mode-alist) + (setq apheleia-mode-alist + (assq-delete-all (car (rassoc name apheleia-mode-alist)) apheleia-mode-alist)))) + (setf (alist-get name apheleia-formatters) args) + (when modes + (dolist (mode modes) + (setf (alist-get mode apheleia-mode-alist) name)))))) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 0e634adbe..1075a98f2 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -1,89 +1,54 @@ ;;; editor/format/config.el -*- lexical-binding: t; -*- -(defvar +format-on-save-enabled-modes - '(not emacs-lisp-mode ; elisp's mechanisms are good enough - sql-mode ; sqlformat is currently broken - tex-mode ; latexindent is broken - latex-mode - org-msg-edit-mode) ; doesn't need a formatter - "A list of major modes in which to reformat the buffer upon saving. - -If this list begins with `not', then it negates the list. -If it is `t', it is enabled in all modes. -If nil, it is disabled in all modes, the same as if the +onsave flag wasn't - used at all. - -Irrelevant if you do not have the +onsave flag enabled for this module.") - (defvar +format-preserve-indentation t "If non-nil, the leading indentation is preserved when formatting the whole buffer. This is particularly useful for partials. Indentation is always preserved when formatting regions.") -(defvar-local +format-with nil - "Set this to explicitly use a certain formatter for the current buffer.") - (defvar +format-with-lsp t "If non-nil, format with LSP formatter if it's available. This can be set buffer-locally with `setq-hook!' to disable LSP formatting in select buffers.") +(defvaralias '+format-with 'apheleia-formatter + "Set this to explicitly use a certain formatter for the current buffer.") + ;; ;;; Bootstrap -(add-to-list 'doom-debug-variables 'format-all-debug) - -(defun +format-enable-on-save-maybe-h () - "Enable formatting on save in certain major modes. - -This is controlled by `+format-on-save-enabled-modes'." - (or (cond ((eq major-mode 'fundamental-mode)) - ((string-prefix-p " " (buffer-name))) - ((and (booleanp +format-on-save-enabled-modes) - (not +format-on-save-enabled-modes))) - ((and (listp +format-on-save-enabled-modes) - (if (eq (car +format-on-save-enabled-modes) 'not) - (memq major-mode (cdr +format-on-save-enabled-modes)) - (not (memq major-mode +format-on-save-enabled-modes))))) - ((not (require 'format-all nil t)))) - (format-all-mode +1))) - (when (modulep! +onsave) - (add-hook 'after-change-major-mode-hook #'+format-enable-on-save-maybe-h)) + (add-hook 'doom-first-file-hook #'apheleia-global-mode)) ;; ;;; Hacks -;; Allow a specific formatter to be used by setting `+format-with', either -;; buffer-locally or let-bound. -(advice-add #'format-all--probe :around #'+format-probe-a) +(defadvice! +format--inhibit-reformat-on-prefix-arg-a (orig-fn &optional arg) + "Make it so \\[save-buffer] with prefix arg inhibits reformatting." + :around #'save-buffer + (let ((apheleia-mode (and apheleia-mode (member arg '(nil 1))))) + (funcall orig-fn))) -;; Doom uses a modded `format-all-buffer', which -;; 1. Enables partial reformatting (while preserving leading indentation), -;; 2. Applies changes via RCS patch, line by line, to protect buffer markers -;; and avoid any jarring cursor+window scrolling. -(advice-add #'format-all-buffer--with :override #'+format-buffer-a) +(add-hook! 'apheleia-post-format-hook + ;; HACK `web-mode' doesn't update syntax highlighting after arbitrary buffer + ;; modifications, so we must trigger refontification manually. + (defun +format--fix-web-mode-fontification-h () + (when (eq major-mode 'web-mode) + (setq web-mode-fontification-off nil) + (when (and web-mode-scan-beg web-mode-scan-end global-font-lock-mode) + (save-excursion + (font-lock-fontify-region web-mode-scan-beg web-mode-scan-end))))) + (defun +format--refresh-git-gutter-h () + (when (bound-and-true-p git-gutter-mode) + (git-gutter)))) -;; format-all-mode "helpfully" raises an error when it doesn't know how to -;; format a buffer. -(add-to-list 'debug-ignored-errors "^Don't know how to format ") -;; Don't pop up imposing warnings about missing formatters, but still log it in -;; to *Messages*. -(defadvice! +format--all-buffer-from-hook-a (fn &rest args) - :around #'format-all-buffer--from-hook - (letf! (defun format-all-buffer--with (formatter mode-result) - (when (or (eq formatter 'lsp) - (eq formatter 'eglot) - (condition-case-unless-debug e - (format-all--formatter-executable formatter) - (error - (message "Warning: cannot reformat buffer because %S isn't installed" - (gethash formatter format-all--executable-table)) - nil))) - (funcall format-all-buffer--with formatter mode-result))) - (apply fn args))) +;; +;;; Additional formatters + +(after! apheleia-mode + ;; TODO html-tidy + ) diff --git a/modules/editor/format/packages.el b/modules/editor/format/packages.el index eada328ac..0f1fd9933 100644 --- a/modules/editor/format/packages.el +++ b/modules/editor/format/packages.el @@ -1,4 +1,5 @@ ;; -*- no-byte-compile: t; -*- ;;; editor/format/packages.el -(package! format-all :pin "47d862d40a088ca089c92cd393c6dca4628f87d3") +;; TODO Pin when this is close to finish +(package! apheleia) diff --git a/modules/editor/format/test/test-format.el b/modules/editor/format/test/test-format.el deleted file mode 100644 index dc2306838..000000000 --- a/modules/editor/format/test/test-format.el +++ /dev/null @@ -1,103 +0,0 @@ -;; -*- no-byte-compile: t; -*- -;;; editor/format/test/test-format.el - -(load! "../autoload/settings") -(load! "../autoload/format") -(require! :editor format) -(require 'format-all) - -;; -(describe "editor/format" - :var (format-all--format-table - format-all--mode-table) - - (before-each - (setq format-all--format-table (make-hash-table) - format-all--mode-table (make-hash-table))) - - (describe "set-formatter!" - (before-each - (set-formatter! 'test (lambda () (interactive)))) - - (it "defines a formatter" - (set-formatter! 'new (lambda () (interactive))) - (expect (gethash 'new format-all--mode-table) :to-equal nil) - (expect (functionp (gethash 'new format-all--format-table)))) - - (it "defines a formatter with modes" - (set-formatter! 'new (lambda () (interactive)) - :modes '(a-mode (b-mode "x"))) - (expect (gethash 'a-mode format-all--mode-table) - :to-equal '((new))) - (expect (gethash 'b-mode format-all--mode-table) - :to-equal '((new . (lambda () "x"))))) - - (it "replaces a pre-existing formatter" - (let ((old-fn (gethash 'test format-all--format-table))) - (set-formatter! 'test "echo") - (expect (gethash 'test format-all--format-table) :not :to-equal old-fn))) - - (it "unsets a pre-existing formatter" - (set-formatter! 'test nil) - (expect (gethash 'test format-all--format-table) :to-be nil)) - - (it "errors when unsetting non-existent formatter" - (expect (set-formatter! 'doesnt-exist nil) :to-throw))) - - - ;; TODO - (xdescribe "hooks" - (describe "format|enable-on-save-maybe") - (describe "format|enable-on-save")) - - - ;; TODO - (xdescribe "formatting" - (before-each - (set-formatter! 'command - (lambda () - (interactive) - (let ((first-line (car (split-string (buffer-string) "\n")))) - (erase-buffer) - (insert first-line))) - :modes '(text-mode)) - (set-formatter! 'faulty-command - (lambda () - (interactive) - (error "This is a test")) - :modes '(text-mode)) - (set-formatter! 'function - (lambda (input) - (insert (car (split-string input "\n"))) - (list nil nil)) - :modes '(text-mode)) - (set-formatter! 'shellcmd "head -n 1" - :modes '(text-mode)) - (set-formatter! 'cmdlist '("head" "-n" "1") - :modes '(text-mode))) - - (describe "with an interactive command" - (it "formats a buffer" ) - (it "formats a region" ) - (it "no-ops if no change" ) - (it "doesn't modify the buffer in case of errors" ) - (it "preserves indentation" )) - - (describe "with a function" - (it "formats a buffer" ) - (it "formats a region" ) - (it "no-ops if no change" ) - (it "doesn't modify the buffer in case of errors" ) - (it "preserves indentation" )) - - (describe "with a shell command") - - (describe "with a shell command list" - (it "formats a buffer" ) - (it "formats a region" ) - (it "no-ops if no change" ) - (it "doesn't modify the buffer in case of errors" ) - (it "preserves indentation" ) - - (it "interpolates non-strings into format strings" ) - (it "conditionally appends sublisted options" )))) diff --git a/modules/lang/ocaml/config.el b/modules/lang/ocaml/config.el index 965955dce..cb5cce429 100644 --- a/modules/lang/ocaml/config.el +++ b/modules/lang/ocaml/config.el @@ -107,8 +107,6 @@ :commands ocamlformat :hook (tuareg-mode-local-vars . +ocaml-init-ocamlformat-h) :config - (set-formatter! 'ocamlformat #'ocamlformat - :modes '(caml-mode tuareg-mode)) ;; TODO Fix region-based formatting support (defun +ocaml-init-ocamlformat-h () (setq +format-with 'ocp-indent) diff --git a/modules/lang/php/config.el b/modules/lang/php/config.el index 20132e1da..5f9d711f3 100644 --- a/modules/lang/php/config.el +++ b/modules/lang/php/config.el @@ -30,7 +30,6 @@ (set-docsets! 'php-mode "PHP" "PHPUnit" "Laravel" "CakePHP" "CodeIgniter" "Doctrine_ORM") (set-repl-handler! 'php-mode #'+php/open-repl) (set-lookup-handlers! 'php-mode :documentation #'php-search-documentation) - (set-formatter! 'php-mode #'php-cs-fixer-fix) (set-ligatures! 'php-mode ;; Functional :lambda "function()" :lambda "fn" diff --git a/modules/lang/sh/config.el b/modules/lang/sh/config.el index 34b7032d5..f87925e3e 100755 --- a/modules/lang/sh/config.el +++ b/modules/lang/sh/config.el @@ -17,10 +17,13 @@ :config (set-docsets! 'sh-mode "Bash") (set-electric! 'sh-mode :words '("else" "elif" "fi" "done" "then" "do" "esac" ";;")) - (set-formatter! 'shfmt - '("shfmt" "-ci" - ("-i" "%d" (unless indent-tabs-mode tab-width)) - ("-ln" "%s" (pcase sh-shell (`bash "bash") (`mksh "mksh") (_ "posix"))))) + (after! apheleia + (setf (alist-get 'shfmt apheleia-formatters) + '("shfmt" "-ci" + (unless indent-tabs-mode + (list "-i" (number-to-string tab-width))) + (list "-ln" (pcase sh-shell (`bash "bash") (`mksh "mksh") (_ "posix")))))) + (set-repl-handler! 'sh-mode #'+sh/open-repl) (set-lookup-handlers! 'sh-mode :documentation #'+sh-lookup-documentation-handler) (set-ligatures! 'sh-mode @@ -85,10 +88,6 @@ ;; whatis lookups are exceptionally slow on macOS (#5860) company-shell-dont-fetch-meta IS-MAC)) -(use-package! fish-mode - :when (modulep! +fish) - :defer t - :config (set-formatter! 'fish-mode #'fish_indent)) (use-package! powershell :when (modulep! +powershell) diff --git a/modules/lang/web/+html.el b/modules/lang/web/+html.el index 2dd0a881d..7baff19db 100644 --- a/modules/lang/web/+html.el +++ b/modules/lang/web/+html.el @@ -27,15 +27,15 @@ ;; tidy is already defined by the format-all package. We redefine it to add ;; more sensible arguments to the tidy command. - (set-formatter! 'html-tidy - '("tidy" "-q" "-indent" - "--tidy-mark" "no" - "--drop-empty-elements" "no" - ("--show-body-only" "%s" (if +format-region-p "true" "auto")) - ("--indent-spaces" "%d" tab-width) - ("--indent-with-tabs" "%s" (if indent-tabs-mode "yes" "no")) - ("-xml" (memq major-mode '(nxml-mode xml-mode)))) - :ok-statuses '(0 1)) + ;; (set-formatter! 'html-tidy + ;; '("tidy" "-q" "-indent" + ;; "--tidy-mark" "no" + ;; "--drop-empty-elements" "no" + ;; ("--show-body-only" "%s" (if +format-region-p "true" "auto")) + ;; ("--indent-spaces" "%d" tab-width) + ;; ("--indent-with-tabs" "%s" (if indent-tabs-mode "yes" "no")) + ;; ("-xml" (memq major-mode '(nxml-mode xml-mode)))) + ;; :ok-statuses '(0 1)) (setq web-mode-enable-html-entities-fontification t web-mode-auto-close-style 1) From 115bfc52a2227b2d1cd0fd2976f594afb42e2781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Mon, 20 Jun 2022 08:57:34 +0100 Subject: [PATCH 02/85] fix(format): correctly adjust shfmt --- modules/lang/sh/config.el | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/lang/sh/config.el b/modules/lang/sh/config.el index f87925e3e..5a5cd7ed5 100755 --- a/modules/lang/sh/config.el +++ b/modules/lang/sh/config.el @@ -17,12 +17,9 @@ :config (set-docsets! 'sh-mode "Bash") (set-electric! 'sh-mode :words '("else" "elif" "fi" "done" "then" "do" "esac" ";;")) - (after! apheleia - (setf (alist-get 'shfmt apheleia-formatters) - '("shfmt" "-ci" - (unless indent-tabs-mode - (list "-i" (number-to-string tab-width))) - (list "-ln" (pcase sh-shell (`bash "bash") (`mksh "mksh") (_ "posix")))))) + (set-formatter! 'shfmt '("shfmt" "-ci" + (unless indent-tabs-mode + (list "-i" (number-to-string tab-width))))) (set-repl-handler! 'sh-mode #'+sh/open-repl) (set-lookup-handlers! 'sh-mode :documentation #'+sh-lookup-documentation-handler) From 3aa9796b84dc975399a73624c6b407897adb7c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sun, 14 Aug 2022 16:17:36 +0100 Subject: [PATCH 03/85] fix(format): resolve list expansion issues The argument list was being expanded incorrectly, this should now be resolved. --- modules/editor/format/autoload/settings.el | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/editor/format/autoload/settings.el b/modules/editor/format/autoload/settings.el index 0406facdb..85c71d354 100644 --- a/modules/editor/format/autoload/settings.el +++ b/modules/editor/format/autoload/settings.el @@ -1,8 +1,7 @@ ;;; editor/format/autoload/settings.el -*- lexical-binding: t; -*- ;;;###autodef -(cl-defun set-formatter! - (name &rest args &key modes filter &allow-other-keys) +(cl-defun set-formatter! (name args &key modes filter) "Define (or modify) a formatter named NAME. Supported keywords: :modes :filter @@ -80,7 +79,10 @@ Advanced examples: (while (rassoc name apheleia-mode-alist) (setq apheleia-mode-alist (assq-delete-all (car (rassoc name apheleia-mode-alist)) apheleia-mode-alist)))) - (setf (alist-get name apheleia-formatters) args) + (let ((formatter (cond + ((listp args) `(,@args)) + (t args)))) + (setf (alist-get name apheleia-formatters) formatter)) (when modes (dolist (mode modes) (setf (alist-get mode apheleia-mode-alist) name)))))) From cd79edf134ed03abbc3190bb56d22c229e011bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sun, 14 Aug 2022 16:26:33 +0100 Subject: [PATCH 04/85] feat(format): add :lang emacs-lisp formatter Introduce a formatter function for emacs-lisp (tracked upstream here [1]) that tries to preserve as much of what the user wants as possible [1]: https://github.com/radian-software/apheleia/pull/102 --- modules/editor/format/config.el | 19 +++++++++++++++++-- modules/lang/emacs-lisp/config.el | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 1075a98f2..d08e51373 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -49,6 +49,21 @@ select buffers.") ;; ;;; Additional formatters -(after! apheleia-mode +(after! apheleia ;; TODO html-tidy - ) + (cl-defun apheleia--indent-lisp-buffer + (&key buffer scratch callback &allow-other-keys) + "Format a Lisp BUFFER. Use SCRATCH as a temporary buffer and CALLBACK to +apply the transformation. For more implementation detail, see +`apheleia--run-formatter-function'." + (with-current-buffer scratch + (setq-local indent-line-function + (buffer-local-value 'indent-line-function buffer)) + (setq-local lisp-indent-function + (buffer-local-value 'lisp-indent-function buffer)) + (funcall (with-current-buffer buffer major-mode)) + (goto-char (point-min)) + (let ((inhibit-message t) + (message-log-max nil)) + (indent-region (point-min) (point-max))) + (funcall callback)))) diff --git a/modules/lang/emacs-lisp/config.el b/modules/lang/emacs-lisp/config.el index b089ff53c..609168518 100644 --- a/modules/lang/emacs-lisp/config.el +++ b/modules/lang/emacs-lisp/config.el @@ -39,6 +39,7 @@ See `+emacs-lisp-non-package-mode' for details.") :documentation #'+emacs-lisp-lookup-documentation) (set-docsets! '(emacs-lisp-mode lisp-interaction-mode) "Emacs Lisp") (set-ligatures! 'emacs-lisp-mode :lambda "lambda") + (set-formatter! 'lisp-indent #'apheleia--indent-lisp-buffer :modes '(emacs-lisp-mode)) (set-rotate-patterns! 'emacs-lisp-mode :symbols '(("t" "nil") ("let" "let*") From bfb963f2f3fcd74650037ff5ea34495406509e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Tue, 16 Aug 2022 08:17:51 +0100 Subject: [PATCH 05/85] feat(format): add :lang cc formatter --- modules/lang/cc/config.el | 12 ++++++++++++ modules/lang/cc/doctor.el | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/modules/lang/cc/config.el b/modules/lang/cc/config.el index 221d7b165..b2cc3739c 100644 --- a/modules/lang/cc/config.el +++ b/modules/lang/cc/config.el @@ -48,6 +48,18 @@ This is ignored by ccls.") (set-docsets! 'c-mode "C") (set-docsets! 'c++-mode "C++" "Boost") (set-electric! '(c-mode c++-mode objc-mode java-mode) :chars '(?\n ?\} ?\{)) + (when (executable-find "clang-format") + (set-formatter! + 'clang-format + '("clang-format" + "-assume-filename" + (or (buffer-file-name) + (cdr (assoc major-mode + '((c-mode . ".c") + (c++-mode . ".cpp") + (cuda-mode . ".cu") + (protobuf-mode . ".proto")))))) + :modes '(c-mode c++-mode protobuf-mode cuda-mode))) (set-rotate-patterns! 'c++-mode :symbols '(("public" "protected" "private") ("class" "struct"))) diff --git a/modules/lang/cc/doctor.el b/modules/lang/cc/doctor.el index f9d2ee687..21c4bba08 100644 --- a/modules/lang/cc/doctor.el +++ b/modules/lang/cc/doctor.el @@ -26,3 +26,7 @@ ;; glslangValidator (unless (executable-find "glslangValidator") (warn! "Couldn't find glslangValidator. GLSL code completion is disabled"))) + +(when (modulep! :editor format) + (unless (executable-find "clang-format") + (warn! "Couldn't find clang-format. Formatting will be disabled."))) From 9a7eae77c8a2a2edc07c337f7858151da8efb641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Tue, 16 Aug 2022 08:14:49 +0100 Subject: [PATCH 06/85] feat(format): add :lang clojure formatter --- modules/lang/clojure/config.el | 3 +++ modules/lang/clojure/doctor.el | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/modules/lang/clojure/config.el b/modules/lang/clojure/config.el index dc51777e5..025d372a6 100644 --- a/modules/lang/clojure/config.el +++ b/modules/lang/clojure/config.el @@ -16,6 +16,9 @@ (use-package! clojure-mode :hook (clojure-mode . rainbow-delimiters-mode) :config + (when (executable-find "zprint") + (set-formatter! 'zprint '("zprint") :modes '(clojure-mode clojurec-mode clojurescript-mode))) + (when (modulep! +lsp) (add-hook! '(clojure-mode-local-vars-hook clojurec-mode-local-vars-hook diff --git a/modules/lang/clojure/doctor.el b/modules/lang/clojure/doctor.el index dff17429e..529c3ba4b 100644 --- a/modules/lang/clojure/doctor.el +++ b/modules/lang/clojure/doctor.el @@ -5,3 +5,7 @@ (not (modulep! +lsp))) (unless (executable-find "clj-kondo") (warn! "Couldn't find clj-kondo. flycheck-clj-kondo will not work."))) + +(when (modulep! :editor format) + (unless (executable-find "zprint") + (warn! "Couldn't find zprint. Formatting will be disabled."))) From 4d51e46c9fd40c944eda6ddee02588c799306615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Mon, 15 Aug 2022 06:34:12 +0100 Subject: [PATCH 07/85] feat(format): add :lang common-lisp formatter --- modules/lang/common-lisp/config.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/common-lisp/config.el b/modules/lang/common-lisp/config.el index f773627cb..07ab50c5b 100644 --- a/modules/lang/common-lisp/config.el +++ b/modules/lang/common-lisp/config.el @@ -26,10 +26,14 @@ (after! lisp-mode (set-repl-handler! 'lisp-mode #'+lisp/open-repl) (set-eval-handler! 'lisp-mode #'sly-eval-region) + (set-formatter! 'lisp-indent #'apheleia--indent-lisp-buffer :modes '(lisp-mode)) (set-lookup-handlers! 'lisp-mode :definition #'sly-edit-definition :documentation #'sly-describe-symbol)) + (add-hook! 'lisp-mode + (after! sly (sly-lisp-indent-compatibility-mode))) + ;; HACK Ensures that sly's contrib modules are loaded as soon as possible, but ;; also as late as possible, so users have an opportunity to override ;; `sly-contrib' in an `after!' block. From 078bf0dd2e15dff0e5e0738bc6a08c8cc60178db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Mon, 15 Aug 2022 07:34:52 +0100 Subject: [PATCH 08/85] feat(format): add :lang crystal formatter --- modules/lang/crystal/config.el | 3 +++ modules/lang/crystal/doctor.el | 3 +++ 2 files changed, 6 insertions(+) diff --git a/modules/lang/crystal/config.el b/modules/lang/crystal/config.el index 255f1a89d..97070ddb4 100644 --- a/modules/lang/crystal/config.el +++ b/modules/lang/crystal/config.el @@ -1,6 +1,9 @@ ;;; lang/crystal/config.el -*- lexical-binding: t; -*- (after! crystal-mode + (when (executable-find "crystal") + (set-formatter! 'crystal-mode '("crystal" "tool" "format" "-") :modes '(crystal-mode))) + (set-lookup-handlers! 'crystal-mode :definition #'crystal-def-jump :references #'crystal-tool-imp) diff --git a/modules/lang/crystal/doctor.el b/modules/lang/crystal/doctor.el index b2f68f86e..23eb9171a 100644 --- a/modules/lang/crystal/doctor.el +++ b/modules/lang/crystal/doctor.el @@ -3,3 +3,6 @@ (unless (executable-find "icr") (warn! "Couldn't find icr. REPL will not work")) + +(unless (executable-find "crystal") + (error! "Couldn't find crystal. Most language features will not work.")) From 53fe5df6b569ca098f9857446d11b1b3b071536f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Tue, 16 Aug 2022 08:18:29 +0100 Subject: [PATCH 09/85] feat(format): add :lang csharp formatter --- modules/lang/csharp/config.el | 5 +++++ modules/lang/csharp/doctor.el | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/modules/lang/csharp/config.el b/modules/lang/csharp/config.el index d68e0a0eb..2a6cf7aa6 100644 --- a/modules/lang/csharp/config.el +++ b/modules/lang/csharp/config.el @@ -3,6 +3,11 @@ (use-package! csharp-mode :hook (csharp-mode . rainbow-delimiters-mode) :config + (when (and (file-exists-p (expand-file-name "~/.dotnet/tools/dotnet-csharpier")) + (file-exists-p ".config/dotnet-tools.json") + (eq 0 (call-process-shell-command + (format "grep -q 'dotnet-csharpier' %s" (expand-file-name ".config/dotnet-tools.json")) nil nil))) + (set-formatter! 'csharpier '("dotnet" "tool" "run" "dotnet-csharpier") :modes '(csharp-mode))) (set-electric! 'csharp-mode :chars '(?\n ?\})) (set-rotate-patterns! 'csharp-mode :symbols '(("public" "protected" "private") diff --git a/modules/lang/csharp/doctor.el b/modules/lang/csharp/doctor.el index e11ceb459..f816be957 100644 --- a/modules/lang/csharp/doctor.el +++ b/modules/lang/csharp/doctor.el @@ -9,3 +9,10 @@ (assert! (or (not (modulep! +tree-sitter)) (modulep! :tools tree-sitter)) "This module requires (:tools tree-sitter)") + +(when (modulep! :editor format) + (unless (and (file-exists-p (expand-file-name "~/.dotnet/tools/dotnet-csharpier")) + (file-exists-p ".config/dotnet-tools.json") + (eq 0 (call-process-shell-command + (format "grep -q 'dotnet-csharpier' %s" (expand-file-name ".config/dotnet-tools.json")) nil nil))) + (warn! "csharpier is not installed or setup as a local tool. Please see the module README. \nOtherwise, formatting will be disabled."))) From f80f52ba4f0361e25d3918ca1d9b80755a4ec006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Tue, 16 Aug 2022 08:19:02 +0100 Subject: [PATCH 10/85] feat(format): add :lang data formatter --- modules/lang/data/config.el | 4 +++- modules/lang/data/doctor.el | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 modules/lang/data/doctor.el diff --git a/modules/lang/data/config.el b/modules/lang/data/config.el index 45ec4f6b1..24498563e 100644 --- a/modules/lang/data/config.el +++ b/modules/lang/data/config.el @@ -8,7 +8,9 @@ (setq nxml-slash-auto-complete-flag t nxml-auto-insert-xml-declaration-flag t) (set-company-backend! 'nxml-mode '(company-nxml company-yasnippet)) - (setq-hook! 'nxml-mode-hook tab-width nxml-child-indent)) + (setq-hook! 'nxml-mode-hook tab-width nxml-child-indent) + (when (executable-find "xmllint") + (set-formatter! 'xmllint '("xmllint" "--format" "-") :modes '(nxml-mode)))) ;;;###package csv-mode diff --git a/modules/lang/data/doctor.el b/modules/lang/data/doctor.el new file mode 100644 index 000000000..b18eb5d54 --- /dev/null +++ b/modules/lang/data/doctor.el @@ -0,0 +1,5 @@ +;;; lang/data/doctor.el -*- lexical-binding: t; -*- + +(when (modulep! :editor format) + (unless (executable-find "xmllint") + (warn! "Couldn't find xmllint. Formatting will be disabled."))) From a9b4f6e21979683a107094c028a9f62a1fdde6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Tue, 16 Aug 2022 08:16:08 +0100 Subject: [PATCH 11/85] feat(format): add :lang erlang formatter --- modules/lang/erlang/config.el | 2 ++ modules/lang/erlang/doctor.el | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/modules/lang/erlang/config.el b/modules/lang/erlang/config.el index edd3fd689..37b9d1ab8 100644 --- a/modules/lang/erlang/config.el +++ b/modules/lang/erlang/config.el @@ -5,6 +5,8 @@ :mode ("/rebar\\.config\\(?:\\.script\\)?\\'" . erlang-mode) :mode ("/\\(?:app\\|sys\\)\\.config\\'" . erlang-mode) :config + (when (executable-find "efmt") + (set-formatter! 'efmt '("efmt" "-") :modes '(erlang-mode))) (when (modulep! +lsp) (add-hook 'erlang-mode-local-vars-hook #'lsp! 'append)) diff --git a/modules/lang/erlang/doctor.el b/modules/lang/erlang/doctor.el index f442e8834..3997f8fa3 100644 --- a/modules/lang/erlang/doctor.el +++ b/modules/lang/erlang/doctor.el @@ -4,3 +4,7 @@ (assert! (or (not (modulep! +lsp)) (modulep! :tools lsp)) "This module requires (:tools lsp)") + +(when (modulep! :editor format) + (unless (executable-find "efmt") + (warn! "Couldn't find efmt. Formatting will be disabled."))) From 12c901cf28e7fdcad82263ef50460a2220a868a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Tue, 16 Aug 2022 08:16:40 +0100 Subject: [PATCH 12/85] feat(format): add :lang gdscript formatter --- modules/lang/gdscript/config.el | 3 +++ modules/lang/gdscript/doctor.el | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 modules/lang/gdscript/doctor.el diff --git a/modules/lang/gdscript/config.el b/modules/lang/gdscript/config.el index 9ab354a7b..55714e65f 100644 --- a/modules/lang/gdscript/config.el +++ b/modules/lang/gdscript/config.el @@ -13,6 +13,9 @@ (set-lookup-handlers! 'gdscript-mode :documentation #'gdscript-docs-browse-symbol-at-point) + (when (executable-find "gdformat") + (set-formatter! 'gdformat '("gdformat" "-") :modes '(gdscript-mode))) + (when (modulep! +lsp) (add-hook 'gdscript-mode-local-vars-hook #'lsp! 'append)) diff --git a/modules/lang/gdscript/doctor.el b/modules/lang/gdscript/doctor.el new file mode 100644 index 000000000..2798524cc --- /dev/null +++ b/modules/lang/gdscript/doctor.el @@ -0,0 +1,5 @@ +;;; lang/gdscript/doctor.el -*- lexical-binding: t; -*- + +(when (modulep! :editor format) + (unless (executable-find "gdformat") + (warn! "Couldn't find gdformat. Formatting will be disabled."))) From efd5ee00eaf0dc73d7bd7ecce3c465498f2e1b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Tue, 16 Aug 2022 08:28:14 +0100 Subject: [PATCH 13/85] feat(format): add :lang fortran formatter --- modules/lang/fortran/config.el | 3 +++ modules/lang/fortran/doctor.el | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/lang/fortran/config.el b/modules/lang/fortran/config.el index 1a1f420b7..15b2400ae 100644 --- a/modules/lang/fortran/config.el +++ b/modules/lang/fortran/config.el @@ -35,6 +35,9 @@ :desc "build" "b" #'+fortran/build :desc "run" "r" #'+fortran/run) + (when (executable-find "fprettify") + (set-formatter! 'fprettify '("fprettify" "-") :modes '(f90-mode fortran-mode))) + (when (modulep! +intel) (map! :map f90-mode-map :localleader diff --git a/modules/lang/fortran/doctor.el b/modules/lang/fortran/doctor.el index 27a12c0c9..976c36a45 100644 --- a/modules/lang/fortran/doctor.el +++ b/modules/lang/fortran/doctor.el @@ -18,6 +18,8 @@ (when (modulep! +lsp) (unless (executable-find "fortls") - (warn! "Couldn't find fortls.")) + (warn! "Couldn't find fortls. Language features will be disabled."))) + +(when (modulep! :editor format) (unless (executable-find "fprettify") - (warn! "Couldn't find fprettify."))) + (warn! "Couldn't find fprettify. Formatting will be disabled."))) From 856d365f2f37c9a85cc94ec69c3f731fe201de51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Tue, 16 Aug 2022 20:08:40 +0100 Subject: [PATCH 14/85] feat(format): add :lang hy formatter --- modules/lang/hy/config.el | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/lang/hy/config.el b/modules/lang/hy/config.el index aac5bcdc1..e17b868d8 100644 --- a/modules/lang/hy/config.el +++ b/modules/lang/hy/config.el @@ -5,4 +5,5 @@ :interpreter "hy" :config (set-repl-handler! 'hy-mode #'hy-shell-start-or-switch-to-shell) + (set-formatter! 'lisp-indent #'apheleia--indent-lisp-buffer :modes '(hy-mode)) (set-company-backend! 'hy-mode 'company-hy)) From 5cbc7a0258eef20914cf135b5aed370f490bc682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Tue, 16 Aug 2022 20:57:40 +0100 Subject: [PATCH 15/85] feat(format): add :lang nim formatter --- modules/lang/nim/config.el | 2 ++ modules/lang/nim/doctor.el | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/lang/nim/config.el b/modules/lang/nim/config.el index 377154627..d15c271c5 100644 --- a/modules/lang/nim/config.el +++ b/modules/lang/nim/config.el @@ -12,6 +12,8 @@ nimsuggest isn't installed." (when (and nimsuggest-path (file-executable-p nimsuggest-path)) (nimsuggest-mode)))) + (set-formatter! 'nmfmt '("nimfmt" filepath) :modes '(nim-mode)) + (when IS-WINDOWS ;; TODO File PR/report upstream (https://github.com/nim-lang/nim-mode) (defadvice! +nim--suggest-get-temp-file-name-a (path) diff --git a/modules/lang/nim/doctor.el b/modules/lang/nim/doctor.el index 788238c98..32980d7ed 100644 --- a/modules/lang/nim/doctor.el +++ b/modules/lang/nim/doctor.el @@ -1,4 +1,4 @@ -;; -*- lexical-binding: t; no-byte-compile: t; -*- + ;;; lang/nim/doctor.el (unless (executable-find "nimsuggest") @@ -7,3 +7,6 @@ (unless (executable-find "nim") (warn! "Could not find nim executable; build commands will be disabled.")) +(when (modulep! :editor format) + (unless (executable-find "nimfmt") + (warn! "Could not find nimfmt. Formatting will be disabled."))) From d1697cb4d9b073dfe4b8c90fc6f210e53556129d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Tue, 16 Aug 2022 21:06:47 +0100 Subject: [PATCH 16/85] feat(format): add :lang purescript formatter --- modules/lang/purescript/config.el | 2 ++ modules/lang/purescript/doctor.el | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 modules/lang/purescript/doctor.el diff --git a/modules/lang/purescript/config.el b/modules/lang/purescript/config.el index e05fd82bc..84d91f618 100644 --- a/modules/lang/purescript/config.el +++ b/modules/lang/purescript/config.el @@ -8,6 +8,8 @@ #'purescript-indentation-mode #'rainbow-delimiters-mode) + (set-formatter! 'purs-tidy '("purs-tidy" "format") :modes '(purescript-mode)) + (map! :localleader :map purescript-mode-map "t" #'psc-ide-show-type diff --git a/modules/lang/purescript/doctor.el b/modules/lang/purescript/doctor.el new file mode 100644 index 000000000..6dac317d3 --- /dev/null +++ b/modules/lang/purescript/doctor.el @@ -0,0 +1,5 @@ +;;; lang/purescript/doctor.el -*- lexical-binding: t; -*- + +(when (modulep! :editor format) + (unless (executable-find "purs-tidy") + (warn! "Could not find purs-tidy. Formatting will be disabled."))) From 7bdf8802a5e3ce2cc40c12310e6250ba84a67eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Tue, 16 Aug 2022 21:24:57 +0100 Subject: [PATCH 17/85] feat(format): add :lang racket formatter --- modules/lang/racket/config.el | 1 + modules/lang/racket/doctor.el | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/modules/lang/racket/config.el b/modules/lang/racket/config.el index 2d890879b..ab5f90489 100644 --- a/modules/lang/racket/config.el +++ b/modules/lang/racket/config.el @@ -21,6 +21,7 @@ :dot ".") (set-rotate-patterns! 'racket-mode :symbols '(("#true" "#false"))) + (set-formatter! 'raco-fmt '("raco" "fmt") :modes '(racket-mode)) (add-hook! 'racket-mode-hook #'rainbow-delimiters-mode diff --git a/modules/lang/racket/doctor.el b/modules/lang/racket/doctor.el index cabeb0d55..6348e7406 100644 --- a/modules/lang/racket/doctor.el +++ b/modules/lang/racket/doctor.el @@ -9,3 +9,8 @@ (unless (executable-find "raco") (warn! "Could not find raco executable; commands for install packages and build libraries will not work.")) + +(when (modulep! :editor format) + (unless (and (executable-find "raco") + (eq 0 (call-process-shell-command "raco fmt --help" nil nil))) + (warn! "Couldn't find raco fmt. Formatting will be disabled."))) From caa6b2bb3b1181d037e40cd64a7b071d8e0b6c09 Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Sat, 31 Dec 2022 23:12:00 +0000 Subject: [PATCH 18/85] feat(format): add :lang rst formatter --- modules/lang/rst/config.el | 4 +++- modules/lang/rst/doctor.el | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 modules/lang/rst/doctor.el diff --git a/modules/lang/rst/config.el b/modules/lang/rst/config.el index 34ea7a0b5..83c74b51f 100644 --- a/modules/lang/rst/config.el +++ b/modules/lang/rst/config.el @@ -1,7 +1,9 @@ ;;; lang/rst/config.el -*- lexical-binding: t; -*- (use-package! sphinx-mode - :hook (rst-mode . sphinx-mode)) + :hook (rst-mode . sphinx-mode) + :config + (set-formatter! 'rstfmt '("rstfmt") :modes '(rst-mode))) (use-package! rst :defer t diff --git a/modules/lang/rst/doctor.el b/modules/lang/rst/doctor.el new file mode 100644 index 000000000..b6b376202 --- /dev/null +++ b/modules/lang/rst/doctor.el @@ -0,0 +1,5 @@ +;;; lang/rst/doctor.el -*- lexical-binding: t; -*- + +(when (modulep! :editor format) + (unless (executable-find "rstfmt") + (warn! "Couldn't find rstfmt. Formatting will be disabled."))) From 3c96f33cb8d43cabea5b01dd8e5c451826da2b4c Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Mon, 24 Jul 2023 19:43:58 +0100 Subject: [PATCH 19/85] feat(format): add :lang scala formatter --- modules/lang/scala/config.el | 2 ++ modules/lang/scala/doctor.el | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/modules/lang/scala/config.el b/modules/lang/scala/config.el index c78a23b3f..d42e879db 100644 --- a/modules/lang/scala/config.el +++ b/modules/lang/scala/config.el @@ -22,6 +22,8 @@ (when (modulep! +tree-sitter) (add-hook 'scala-mode-local-vars-hook #'tree-sitter! 'append)) + (set-formatter! 'scalafmt '("scalafmt" "--stdin") :modes '(scala-mode)) + (set-ligatures! 'scala-mode ;; Functional :def "def" diff --git a/modules/lang/scala/doctor.el b/modules/lang/scala/doctor.el index 917a129bd..fc72e2f18 100644 --- a/modules/lang/scala/doctor.el +++ b/modules/lang/scala/doctor.el @@ -11,3 +11,7 @@ (if (and (modulep! +lsp) (not (executable-find "metals"))) (warn! "metals isn't installed")) + +(when (modulep! :editor format) + (unless (executable-find "scalafmt") + (warn! "Couldn't find scalafmt. Formatting will be disabled."))) From d8dc579fcba3670a460c0329d3b7536d72431650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 17 Aug 2022 07:45:26 +0100 Subject: [PATCH 20/85] feat(format): add :lang scheme formatter --- modules/lang/scheme/config.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/lang/scheme/config.el b/modules/lang/scheme/config.el index 47fa31337..17e189f1f 100644 --- a/modules/lang/scheme/config.el +++ b/modules/lang/scheme/config.el @@ -3,7 +3,9 @@ (use-package! scheme :interpreter ("scsh" . scheme-mode) :hook (scheme-mode . rainbow-delimiters-mode) - :config (advice-add #'scheme-indent-function :override #'+scheme-indent-function-a)) + :config + (set-formatter! 'lisp-indent #'apheleia--indent-lisp-buffer :modes '(scheme-mode)) + (advice-add #'scheme-indent-function :override #'+scheme-indent-function-a)) (use-package! geiser From 7b46177d197cb2bdd2460d43fa39c9b09416c60f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 17 Aug 2022 07:51:34 +0100 Subject: [PATCH 21/85] feat(format): add :lang sml formatter --- modules/lang/sml/config.el | 1 + modules/lang/sml/doctor.el | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 modules/lang/sml/doctor.el diff --git a/modules/lang/sml/config.el b/modules/lang/sml/config.el index 7a5d69e04..9755cd33e 100644 --- a/modules/lang/sml/config.el +++ b/modules/lang/sml/config.el @@ -4,6 +4,7 @@ :mode "\\.s\\(?:ml\\|ig\\)\\'" :config (set-repl-handler! 'sml-mode #'run-sml) + (set-formatter! 'smlformat '("smlformat") :modes '(sml-mode)) ;; don't auto-close apostrophes (type 'a = foo) and backticks (`Foo) (sp-with-modes 'sml-mode diff --git a/modules/lang/sml/doctor.el b/modules/lang/sml/doctor.el new file mode 100644 index 000000000..de483c420 --- /dev/null +++ b/modules/lang/sml/doctor.el @@ -0,0 +1,5 @@ +;;; lang/sml/doctor.el -*- lexical-binding: t; -*- + +(when (modulep! :editor format) + (unless (executable-find "smlformat") + (warn! "Couldn't find smlformat. Formatting will be disabled."))) From c2980d1d7b767e195e055ebe4e25e7148b90d487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 17 Aug 2022 07:58:05 +0100 Subject: [PATCH 22/85] feat(format): add :lang swift formatter --- modules/lang/swift/config.el | 1 + modules/lang/swift/doctor.el | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/modules/lang/swift/config.el b/modules/lang/swift/config.el index 2e721ec18..912898172 100644 --- a/modules/lang/swift/config.el +++ b/modules/lang/swift/config.el @@ -27,6 +27,7 @@ :after swift-mode :init (add-hook 'swift-mode-local-vars-hook #'lsp! 'append) :config + (set-formatter! 'swiftformat '("swiftformat" "--output" "stdout")) (setq lsp-sourcekit-executable (cl-find-if #'executable-find (list lsp-sourcekit-executable ; 'sourcekit-lsp' by default diff --git a/modules/lang/swift/doctor.el b/modules/lang/swift/doctor.el index 15b420de4..3e2881b5b 100644 --- a/modules/lang/swift/doctor.el +++ b/modules/lang/swift/doctor.el @@ -3,3 +3,7 @@ (assert! (or (not (modulep! +tree-sitter)) (modulep! :tools tree-sitter)) "This module requires (:tools tree-sitter)") + +(when (modulep! :editor format) + (unless (executable-find "swiftformat") + (warn! "Couldn't find swiftformat. Formatting will be disabled."))) From c7794ba06c46e99147c4dcebb4f8450fcfd8587a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 17 Aug 2022 08:04:55 +0100 Subject: [PATCH 23/85] feat(format): add :lang zig formatter --- modules/lang/zig/config.el | 1 + modules/lang/zig/doctor.el | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/lang/zig/config.el b/modules/lang/zig/config.el index 71f2b7657..a9f21522f 100644 --- a/modules/lang/zig/config.el +++ b/modules/lang/zig/config.el @@ -11,6 +11,7 @@ :hook (zig-mode . rainbow-delimiters-mode) :config (setq zig-format-on-save nil) ; rely on :editor format instead + (set-formatter! 'zigfmt '("zig" "fmt" "--stdin") :modes '(zig-mode)) (when (modulep! +lsp) (add-hook 'zig-mode-local-vars-hook #'lsp! 'append)) diff --git a/modules/lang/zig/doctor.el b/modules/lang/zig/doctor.el index 361e4d69c..38b1bec3a 100644 --- a/modules/lang/zig/doctor.el +++ b/modules/lang/zig/doctor.el @@ -10,7 +10,10 @@ "This module requires (:tools tree-sitter)") (unless (executable-find "zig") - (warn! "Couldn't find zig binary")) + (warn! "Couldn't find zig binary") + + (when (modulep! :editor format) + (warn! "Formatting will be disabled"))) (when (modulep! +lsp) (unless (executable-find "zls") From 7e15504163d03594c23e565ca4c2cae027e43bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 17 Aug 2022 08:20:58 +0100 Subject: [PATCH 24/85] feat(format): add :tools docker formatter --- modules/tools/docker/config.el | 1 + modules/tools/docker/doctor.el | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 modules/tools/docker/doctor.el diff --git a/modules/tools/docker/config.el b/modules/tools/docker/config.el index 5f520a7d6..d030acd85 100644 --- a/modules/tools/docker/config.el +++ b/modules/tools/docker/config.el @@ -2,6 +2,7 @@ (after! dockerfile-mode (set-docsets! 'dockerfile-mode "Docker") + (set-formatter! 'dockfmt '("dockfmt" "fmt" filepath) :modes '(dockerfile-mode)) (when (modulep! +lsp) (add-hook 'dockerfile-mode-local-vars-hook #'lsp! 'append))) diff --git a/modules/tools/docker/doctor.el b/modules/tools/docker/doctor.el new file mode 100644 index 000000000..d84713e7c --- /dev/null +++ b/modules/tools/docker/doctor.el @@ -0,0 +1,5 @@ +;;; tools/docker/doctor.el -*- lexical-binding: t; -*- + +(when (modulep! :editor format) + (unless (executable-find "dockfmt") + (warn! "Couldn't find dockfmt. Formatting will be disabled."))) From dc3b5c3710ac906afec00347061d42c4b744c512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 7 Sep 2022 22:23:34 +0100 Subject: [PATCH 25/85] fix(format): handle git-gutter nicely --- modules/editor/format/config.el | 21 ++++++++++----------- modules/ui/vc-gutter/config.el | 8 ++++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index d08e51373..94aa46dba 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -33,17 +33,16 @@ select buffers.") (funcall orig-fn))) (add-hook! 'apheleia-post-format-hook - ;; HACK `web-mode' doesn't update syntax highlighting after arbitrary buffer - ;; modifications, so we must trigger refontification manually. - (defun +format--fix-web-mode-fontification-h () - (when (eq major-mode 'web-mode) - (setq web-mode-fontification-off nil) - (when (and web-mode-scan-beg web-mode-scan-end global-font-lock-mode) - (save-excursion - (font-lock-fontify-region web-mode-scan-beg web-mode-scan-end))))) - (defun +format--refresh-git-gutter-h () - (when (bound-and-true-p git-gutter-mode) - (git-gutter)))) + ;; HACK `web-mode' doesn't update syntax highlighting after arbitrary buffer + ;; modifications, so we must trigger refontification manually. + (defun +format--fix-web-mode-fontification-h () + (when (eq major-mode 'web-mode) + (setq web-mode-fontification-off nil) + (when (and web-mode-scan-beg web-mode-scan-end global-font-lock-mode) + (save-excursion + (font-lock-fontify-region web-mode-scan-beg web-mode-scan-end))))) + (defun +format--refresh-git-gutter-h () + (+vc-gutter-init-maybe-h))) ;; diff --git a/modules/ui/vc-gutter/config.el b/modules/ui/vc-gutter/config.el index 0f3b2bea1..cd78a4f59 100644 --- a/modules/ui/vc-gutter/config.el +++ b/modules/ui/vc-gutter/config.el @@ -116,6 +116,11 @@ is deferred until the file is saved. Respects `git-gutter:disabled-modes'." ;; UX: update git-gutter on focus (in case I was using git externally) (add-hook 'focus-in-hook #'git-gutter:update-all-windows) + ;; Stop git-gutter doing things when we don't want + (remove-hook 'post-command-hook #'git-gutter:post-command-hook) + (advice-remove #'quit-window #'git-gutter:quit-window) + (advice-remove #'switch-to-buffer #'git-gutter:switch-to-buffer) + (add-hook! '(doom-escape-hook doom-switch-window-hook) :append (defun +vc-gutter-update-h (&rest _) "Refresh git-gutter on ESC. Return nil to prevent shadowing other @@ -130,6 +135,9 @@ is deferred until the file is saved. Respects `git-gutter:disabled-modes'." (advice-add #'magit-stage-file :after #'+vc-gutter-update-h) (advice-add #'magit-unstage-file :after #'+vc-gutter-update-h) + ;; UX: update git-gutter after reverting a buffer + (add-hook 'after-revert-hook #'+vc-gutter-update-h) + ;; FIX: stop git-gutter:{next,previous}-hunk from jumping to random hunks. (defadvice! +vc-gutter--fix-linearity-of-hunks-a (diffinfos is-reverse) :override #'git-gutter:search-near-diff-index From 9093f986dcc9792b2abf8323ecd673945f61127a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sun, 25 Sep 2022 11:17:08 +0100 Subject: [PATCH 26/85] docs(beancount): Add formatter docs --- modules/lang/beancount/README.org | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/lang/beancount/README.org b/modules/lang/beancount/README.org index 77e89581f..dc2eb211e 100644 --- a/modules/lang/beancount/README.org +++ b/modules/lang/beancount/README.org @@ -34,6 +34,7 @@ you [[https://plaintextaccounting.org/][manage your money in plain text]]. This module requires: - [[https://github.com/beancount/beancount][beancount]], for generating reports - [[https://beancount.github.io/fava/][fava]], for a web interface for your ledgers +- [[doom-executable:bean-format]], if [[doom-module::editor format]] * TODO Usage #+begin_quote From c9d9051ef9e1d79eb088315b2c21a444e32404e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sun, 25 Sep 2022 11:29:27 +0100 Subject: [PATCH 27/85] docs(cc): Add formatter docs --- modules/lang/cc/README.org | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/lang/cc/README.org b/modules/lang/cc/README.org index cd673da23..8e7100e7b 100644 --- a/modules/lang/cc/README.org +++ b/modules/lang/cc/README.org @@ -133,6 +133,11 @@ rdm & rc -J $PROJECT_ROOT # loads PROJECT_ROOT's compile_commands.json #+end_src +** =:editor format= +The formatter used is [[doom-executable:clang-format]] which should be installed alongside =clang=. + +For more info, see [[doom-module::editor format]]. + * TODO Usage #+begin_quote 🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]] From be26181d4f7e36dca600f6004ed3abaa086bac90 Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Fri, 24 Feb 2023 14:04:23 +0000 Subject: [PATCH 28/85] docs(clojure): add formatter docs --- modules/lang/clojure/README.org | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/lang/clojure/README.org b/modules/lang/clojure/README.org index 453fc904c..fe6a01777 100644 --- a/modules/lang/clojure/README.org +++ b/modules/lang/clojure/README.org @@ -47,6 +47,7 @@ This module requires: - [[https://clojure-lsp.github.io/clojure-lsp/][clojure-lsp]], for LSP support (if [[doom-module:+lsp]]) - [[https://github.com/babashka/neil][neil]] for the ability to add packages to your Clojure project from Emacs - [[https://github.com/borkdude/jet][jet]] for jet integration +- [[https://github.com/weavejester/cljfmt][cljfmt]], for formatting code (if [[doom-module::editor format]]) * Usage From d8dcac6908f0bbc1e351342c5c62930f67949e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 5 Oct 2022 11:54:47 +0100 Subject: [PATCH 29/85] docs(common-lisp): add formatter docs --- modules/lang/common-lisp/README.org | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/lang/common-lisp/README.org b/modules/lang/common-lisp/README.org index 2bb211fff..f5d3e0757 100644 --- a/modules/lang/common-lisp/README.org +++ b/modules/lang/common-lisp/README.org @@ -59,6 +59,12 @@ This module also enables the evaluation of =lisp= source blocks in Org Mode. However, you will need a running Sly session for this to work. ~M-x sly~ starts such a session if you didn't have one open already. +** formatter +By enabling [[doom-module::editor format]], [[fn:apheleia-indent-lisp-buffer]] will be +used to format the current buffer. + +Enable [[doom-module::editor format +onsave]] to format the buffer on save. + * TODO Configuration #+begin_quote 🔨 /This module's configuration documentation is incomplete./ [[doom-contrib-module:][Complete it?]] From ebfc1905592ff2df9c90fc4bf9cecfea0ca99e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 5 Oct 2022 12:06:07 +0100 Subject: [PATCH 30/85] docs(crystal): add formatter docs --- modules/lang/crystal/README.org | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/lang/crystal/README.org b/modules/lang/crystal/README.org index 9b4122da5..eb90ce7f0 100644 --- a/modules/lang/crystal/README.org +++ b/modules/lang/crystal/README.org @@ -48,6 +48,12 @@ This module requires: 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] #+end_quote +** formatter +By enabling [[doom-module::editor format]], [[doom-package:apheleia]] will be +used to format the current buffer. + +Enable [[doom-module::editor format +onsave]] to format the buffer on save. + * TODO Configuration #+begin_quote 🔨 This module has no configuration documentation yet. [[doom-contrib-module:][Write some?]] From 274b6e2d4d430cd402ea8449294643de852a2a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 5 Oct 2022 12:18:16 +0100 Subject: [PATCH 31/85] docs(csharp): add formatter docs --- modules/lang/csharp/README.org | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/lang/csharp/README.org b/modules/lang/csharp/README.org index a122fd7c6..eae446653 100644 --- a/modules/lang/csharp/README.org +++ b/modules/lang/csharp/README.org @@ -45,15 +45,22 @@ This module requires: - .NET SDKs (on Windows) - .NET Core 1.X - 3.X or .NET 5 for cross platform - omnisharp-rosyln (if [[doom-module:+lsp]]) +- [[doom-executable:csharpier]] (if [[doom-module::editor format]]) -** TODO MacOS +** mono +*** TODO MacOS -** Arch Linux +*** Arch Linux #+begin_src sh pacman --needed --noconfirm -S mono #+end_src -** TODO NixOS +*** TODO NixOS + +** csharpier +#+begin_src shell +dotnet tool install csharpier -g +#+end_src * TODO Usage #+begin_quote From d38489b02d16ad20cef58f54751100c0acf7b403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 5 Oct 2022 12:21:12 +0100 Subject: [PATCH 32/85] docs(dart): add formatter docs --- modules/lang/dart/README.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lang/dart/README.org b/modules/lang/dart/README.org index 0ca04e04b..add6a0a13 100644 --- a/modules/lang/dart/README.org +++ b/modules/lang/dart/README.org @@ -87,7 +87,7 @@ flutter doctor # for Dependency check and further instructions 🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]] #+end_quote -- Syntax highlighting and formatting for ~.dart~ files provided by LSP. +- Syntax highlighting and formatting for ~.dart~ files provided by LSP or [[doom-module::editor format]]. - Auto import. - Widget guide lines for Flutter. - Closing labels for constructors. From e4faa8f2a45eb7a39e217a7103c29f0c97f976a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 5 Oct 2022 12:36:59 +0100 Subject: [PATCH 33/85] docs(elixir): add formatter docs --- modules/lang/elixir/README.org | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/lang/elixir/README.org b/modules/lang/elixir/README.org index d4850645b..966fa48df 100644 --- a/modules/lang/elixir/README.org +++ b/modules/lang/elixir/README.org @@ -74,6 +74,7 @@ zypper install elixir - Phoenix support - ~iex~ integration ([[doom-module::tools eval]]) - Syntax checking ([[doom-module::checkers syntax]], using [[doom-package:flycheck-credo]]) +- Formatting for elixir files provided by [[doom-module::editor format]]. ** exunit-mode The exunit-mode prefix is [[kbd:][ t]]. Here is some examples: From 659b6ff6ddad7e6818b27778b481be99fb37ef90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 5 Oct 2022 12:43:36 +0100 Subject: [PATCH 34/85] docs(elm): add formatter docs --- modules/lang/elm/README.org | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/lang/elm/README.org b/modules/lang/elm/README.org index 873ed3901..0405df08b 100644 --- a/modules/lang/elm/README.org +++ b/modules/lang/elm/README.org @@ -43,6 +43,12 @@ This module adds [[https://elm-lang.org/][Elm]] support to Doom Emacs. 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] #+end_quote +** formatter +By enabling [[doom-module::editor format]], [[doom-package:apheleia]] will be +used to format the current buffer. + +Enable [[doom-module::editor format +onsave]] to format the buffer on save. + * TODO Configuration #+begin_quote 🔨 This module has no configuration documentation yet. [[doom-contrib-module:][Write some?]] From 0a79b40443d996123ae0a73298a62076f2c027c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 5 Oct 2022 12:48:26 +0100 Subject: [PATCH 35/85] docs(emacs-lisp): add formatter docs --- modules/lang/emacs-lisp/README.org | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/lang/emacs-lisp/README.org b/modules/lang/emacs-lisp/README.org index 827278bb9..73603ffa5 100644 --- a/modules/lang/emacs-lisp/README.org +++ b/modules/lang/emacs-lisp/README.org @@ -56,6 +56,12 @@ about it. 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] #+end_quote +** formatter +By enabling [[doom-module::editor format]], [[doom-package:apheleia]] will be +used to format the current buffer. + +Enable [[doom-module::editor format +onsave]] to format the buffer on save. + * TODO Configuration #+begin_quote 🔨 This module has no configuration documentation yet. [[doom-contrib-module:][Write some?]] From 508765002b4142285427333171afe7aeea7bc58b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 5 Oct 2022 12:56:32 +0100 Subject: [PATCH 36/85] docs(erlang): add formatter docs --- modules/lang/erlang/README.org | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/lang/erlang/README.org b/modules/lang/erlang/README.org index 3a2b6be03..530643745 100644 --- a/modules/lang/erlang/README.org +++ b/modules/lang/erlang/README.org @@ -39,13 +39,20 @@ Includes: This module requires Erlang be installed (which includes ~erlang-mode~). Check your distribution's package manager or a version management tool such as [[https://github.com/kerl/kerl][kerl]]. -For LSP support, install [[https://github.com/erlang/sourcer][sourcer]]. +- [[https://github.com/erlang/sourcer][sourcer]] when [[doom-module::tools lsp]] & [[doom-module:+lsp]] +- [[https://github.com/sile/efmt][efmt]] when [[doom-module::editor format]] * TODO Usage #+begin_quote 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] #+end_quote +** formatter +By enabling [[doom-module::editor format]], [[doom-package:apheleia]] will be +used to format the current buffer. + +Enable [[doom-module::editor format +onsave]] to format the buffer on save. + * TODO Configuration #+begin_quote 🔨 This module has no configuration documentation yet. [[doom-contrib-module:][Write some?]] From d2f3190766a755c5e4b071283f1d55e9c9e738e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Wed, 5 Oct 2022 13:00:32 +0100 Subject: [PATCH 37/85] docs(fortran): add formatter docs --- modules/lang/fortran/README.org | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/lang/fortran/README.org b/modules/lang/fortran/README.org index ac46501c0..bdcdb9803 100644 --- a/modules/lang/fortran/README.org +++ b/modules/lang/fortran/README.org @@ -97,6 +97,11 @@ your Bash Profile, etc., and log out and in again._ Now Doom will be able to use Good luck and happy computing! +** efmt +When [[doom-module::editor format]] is enabled and [[doom-executable:fprettify]] is installed, buffers can be formatted with [[fn:apheleia-format-buffer]]. + +Enable [[doom-module::editor format +onsave]] to format the buffer on save. + * TODO Usage #+begin_quote 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] From ca38e5a9a5cf5a0aab21908ef611c5ed3bcf9008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Thu, 17 Nov 2022 17:03:12 +0000 Subject: [PATCH 38/85] feat(format): add :lang fsharp formatter --- modules/lang/fsharp/config.el | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/lang/fsharp/config.el b/modules/lang/fsharp/config.el index 127f66840..6b79db3f8 100644 --- a/modules/lang/fsharp/config.el +++ b/modules/lang/fsharp/config.el @@ -11,6 +11,7 @@ (set-lookup-handlers! 'fsharp-mode :async t :definition #'fsharp-ac/gotodefn-at-point) (set-company-backend! 'fsharp-mode 'fsharp-ac/company-backend)) (set-repl-handler! 'fsharp-mode #'run-fsharp) + (set-formatter! 'fantomas '("fantomas" "--stdin") :modes '(fsharp-mode)) (map! :localleader :map fsharp-mode-map "b" #'fsharp-ac/pop-gotodefn-stack ; Useful for re-tracing your steps From 26819c33f379f7341c3cd6e9b15c4aa7735f2ae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Thu, 17 Nov 2022 17:03:25 +0000 Subject: [PATCH 39/85] docs(fsharp): add formatter docs --- modules/lang/fsharp/README.org | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/lang/fsharp/README.org b/modules/lang/fsharp/README.org index b528ab980..80cb711a7 100644 --- a/modules/lang/fsharp/README.org +++ b/modules/lang/fsharp/README.org @@ -48,6 +48,13 @@ pacman -S mono ** LSP The language server is automatically installed by [[https://github.com/emacs-lsp/lsp-mode/blob/master/clients/lsp-fsharp.el][lsp-fsharp]]. +** Fantomas +Fantomas is used for formatting via [[doom-module::editor format]] and can be installed as a [[https://dotnet.microsoft.com/en-us/download][dotnet]] tool. + +#+begin_src shell +dotnet tool install -g fantomas-tool +#+end_src + * TODO Usage #+begin_quote 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] From cc9bda36c273a0cd8194d84cfff5fcc2e4271601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Thu, 17 Nov 2022 17:04:50 +0000 Subject: [PATCH 40/85] fix(cc): remove executable-find formatter check --- modules/lang/cc/config.el | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/modules/lang/cc/config.el b/modules/lang/cc/config.el index b2cc3739c..d56bcb3e1 100644 --- a/modules/lang/cc/config.el +++ b/modules/lang/cc/config.el @@ -48,18 +48,17 @@ This is ignored by ccls.") (set-docsets! 'c-mode "C") (set-docsets! 'c++-mode "C++" "Boost") (set-electric! '(c-mode c++-mode objc-mode java-mode) :chars '(?\n ?\} ?\{)) - (when (executable-find "clang-format") - (set-formatter! - 'clang-format - '("clang-format" - "-assume-filename" - (or (buffer-file-name) - (cdr (assoc major-mode - '((c-mode . ".c") - (c++-mode . ".cpp") - (cuda-mode . ".cu") - (protobuf-mode . ".proto")))))) - :modes '(c-mode c++-mode protobuf-mode cuda-mode))) + (set-formatter! + 'clang-format + '("clang-format" + "-assume-filename" + (or (buffer-file-name) + (cdr (assoc major-mode + '((c-mode . ".c") + (c++-mode . ".cpp") + (cuda-mode . ".cu") + (protobuf-mode . ".proto")))))) + :modes '(c-mode c++-mode protobuf-mode cuda-mode)) (set-rotate-patterns! 'c++-mode :symbols '(("public" "protected" "private") ("class" "struct"))) From 65b0b148497c1b1a1e5f1e2e95eda7862b12b095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Thu, 17 Nov 2022 17:05:50 +0000 Subject: [PATCH 41/85] fix(crystal): remove executable-find formatter check --- modules/lang/crystal/config.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/lang/crystal/config.el b/modules/lang/crystal/config.el index 97070ddb4..979d27944 100644 --- a/modules/lang/crystal/config.el +++ b/modules/lang/crystal/config.el @@ -1,8 +1,7 @@ ;;; lang/crystal/config.el -*- lexical-binding: t; -*- (after! crystal-mode - (when (executable-find "crystal") - (set-formatter! 'crystal-mode '("crystal" "tool" "format" "-") :modes '(crystal-mode))) + (set-formatter! 'crystal-mode '("crystal" "tool" "format" "-") :modes '(crystal-mode)) (set-lookup-handlers! 'crystal-mode :definition #'crystal-def-jump From a5756f1e19df47c0d919b4a5399bd816c3381278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Thu, 17 Nov 2022 17:31:04 +0000 Subject: [PATCH 42/85] fix(csharp): reduce formatter complexity --- modules/lang/csharp/config.el | 6 +----- modules/lang/csharp/doctor.el | 7 ++----- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/modules/lang/csharp/config.el b/modules/lang/csharp/config.el index 2a6cf7aa6..94f64cc61 100644 --- a/modules/lang/csharp/config.el +++ b/modules/lang/csharp/config.el @@ -3,11 +3,7 @@ (use-package! csharp-mode :hook (csharp-mode . rainbow-delimiters-mode) :config - (when (and (file-exists-p (expand-file-name "~/.dotnet/tools/dotnet-csharpier")) - (file-exists-p ".config/dotnet-tools.json") - (eq 0 (call-process-shell-command - (format "grep -q 'dotnet-csharpier' %s" (expand-file-name ".config/dotnet-tools.json")) nil nil))) - (set-formatter! 'csharpier '("dotnet" "tool" "run" "dotnet-csharpier") :modes '(csharp-mode))) + (set-formatter! 'csharpier '("dotnet-csharpier") :modes '(csharp-mode)) (set-electric! 'csharp-mode :chars '(?\n ?\})) (set-rotate-patterns! 'csharp-mode :symbols '(("public" "protected" "private") diff --git a/modules/lang/csharp/doctor.el b/modules/lang/csharp/doctor.el index f816be957..3d7b2be35 100644 --- a/modules/lang/csharp/doctor.el +++ b/modules/lang/csharp/doctor.el @@ -11,8 +11,5 @@ "This module requires (:tools tree-sitter)") (when (modulep! :editor format) - (unless (and (file-exists-p (expand-file-name "~/.dotnet/tools/dotnet-csharpier")) - (file-exists-p ".config/dotnet-tools.json") - (eq 0 (call-process-shell-command - (format "grep -q 'dotnet-csharpier' %s" (expand-file-name ".config/dotnet-tools.json")) nil nil))) - (warn! "csharpier is not installed or setup as a local tool. Please see the module README. \nOtherwise, formatting will be disabled."))) + (unless (executable-find "dotnet-csharpier") + (warn! "csharpier is not installed, formatting will be disabled."))) From 9c2d0b00d74b4307fc7145057fc8aef5f222427a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Thu, 17 Nov 2022 17:32:59 +0000 Subject: [PATCH 43/85] fix(data): remove executable-find formatter check --- modules/lang/data/config.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/lang/data/config.el b/modules/lang/data/config.el index 24498563e..d0777a910 100644 --- a/modules/lang/data/config.el +++ b/modules/lang/data/config.el @@ -9,8 +9,7 @@ nxml-auto-insert-xml-declaration-flag t) (set-company-backend! 'nxml-mode '(company-nxml company-yasnippet)) (setq-hook! 'nxml-mode-hook tab-width nxml-child-indent) - (when (executable-find "xmllint") - (set-formatter! 'xmllint '("xmllint" "--format" "-") :modes '(nxml-mode)))) + (set-formatter! 'xmllint '("xmllint" "--format" "-") :modes '(nxml-mode))) ;;;###package csv-mode From c6291ecfc069f1cb1ac0a76d62a2fd37bb6de03d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Thu, 17 Nov 2022 17:35:26 +0000 Subject: [PATCH 44/85] fix(erlang): remove executable-find formatter check --- modules/lang/erlang/config.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/lang/erlang/config.el b/modules/lang/erlang/config.el index 37b9d1ab8..672ca5b6a 100644 --- a/modules/lang/erlang/config.el +++ b/modules/lang/erlang/config.el @@ -5,8 +5,7 @@ :mode ("/rebar\\.config\\(?:\\.script\\)?\\'" . erlang-mode) :mode ("/\\(?:app\\|sys\\)\\.config\\'" . erlang-mode) :config - (when (executable-find "efmt") - (set-formatter! 'efmt '("efmt" "-") :modes '(erlang-mode))) + (set-formatter! 'efmt '("efmt" "-") :modes '(erlang-mode)) (when (modulep! +lsp) (add-hook 'erlang-mode-local-vars-hook #'lsp! 'append)) From e44a7b3c5b1f8b010f397b5465bc4f93c128133c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Thu, 17 Nov 2022 17:35:59 +0000 Subject: [PATCH 45/85] fix(fortran): remove executable-find formatter check --- modules/lang/fortran/config.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/lang/fortran/config.el b/modules/lang/fortran/config.el index 15b2400ae..b42e76ad6 100644 --- a/modules/lang/fortran/config.el +++ b/modules/lang/fortran/config.el @@ -35,8 +35,7 @@ :desc "build" "b" #'+fortran/build :desc "run" "r" #'+fortran/run) - (when (executable-find "fprettify") - (set-formatter! 'fprettify '("fprettify" "-") :modes '(f90-mode fortran-mode))) + (set-formatter! 'fprettify '("fprettify" "-") :modes '(f90-mode fortran-mode)) (when (modulep! +intel) (map! :map f90-mode-map From d92219d8d8bfaa2963f1adc3c46102a190c60c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Thu, 17 Nov 2022 17:36:30 +0000 Subject: [PATCH 46/85] fix(gdscript): remove executable-find formatter check --- modules/lang/gdscript/config.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/lang/gdscript/config.el b/modules/lang/gdscript/config.el index 55714e65f..f8496eeba 100644 --- a/modules/lang/gdscript/config.el +++ b/modules/lang/gdscript/config.el @@ -13,8 +13,7 @@ (set-lookup-handlers! 'gdscript-mode :documentation #'gdscript-docs-browse-symbol-at-point) - (when (executable-find "gdformat") - (set-formatter! 'gdformat '("gdformat" "-") :modes '(gdscript-mode))) + (set-formatter! 'gdformat '("gdformat" "-") :modes '(gdscript-mode)) (when (modulep! +lsp) (add-hook 'gdscript-mode-local-vars-hook #'lsp! 'append)) From e3a337ebd438e3ee3bdb27a9864064f87b301044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Thu, 17 Nov 2022 17:40:27 +0000 Subject: [PATCH 47/85] fix!(go): prefer upstream formatter config BREAKING CHANGE: Since apheleia doesn't handle regions yet, this should be fine to leave to upstream. This could be considered a breaking change if users rely on this functionality. --- modules/lang/go/config.el | 8 -------- 1 file changed, 8 deletions(-) diff --git a/modules/lang/go/config.el b/modules/lang/go/config.el index 525444a81..dc66af7b2 100644 --- a/modules/lang/go/config.el +++ b/modules/lang/go/config.el @@ -11,14 +11,6 @@ :references #'go-guru-referrers :documentation #'godoc-at-point) - ;; Redefines default formatter to *not* use goimports if reformatting a - ;; region; as it doesn't play well with partial code. - (set-formatter! 'gofmt - '(("%s" (if (or +format-region-p - (not (executable-find "goimports"))) - "gofmt" - "goimports")))) - (if (modulep! +lsp) (add-hook 'go-mode-local-vars-hook #'lsp! 'append) (add-hook 'go-mode-hook #'go-eldoc-setup)) From 09d0f8b984579cb581a5de46f06d6521a7502e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 09:38:26 +0000 Subject: [PATCH 48/85] docs(graphql): add formatter docs --- modules/lang/graphql/README.org | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/lang/graphql/README.org b/modules/lang/graphql/README.org index 772c13fd3..5f8c6255c 100644 --- a/modules/lang/graphql/README.org +++ b/modules/lang/graphql/README.org @@ -43,9 +43,15 @@ It includes: * Installation [[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]] +** LSP + This module has no direct requirements, but the +lsp flag requires a [[https://emacs-lsp.github.io/lsp-mode/page/lsp-graphql/][supported LSP server]]. +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://prettier.io/docs/en/install.html][prettier]]. + * Usage ** Sending queries When visiting a graphql buffer, you have access to the ability to send the From dd4c0b385f9b81c829d84d6c6d6ef5f2a16fc1c6 Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Fri, 24 Feb 2023 14:09:16 +0000 Subject: [PATCH 49/85] docs(haskell): add formatter docs --- modules/lang/haskell/README.org | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/lang/haskell/README.org b/modules/lang/haskell/README.org index 0e089a69d..4bbcbd628 100644 --- a/modules/lang/haskell/README.org +++ b/modules/lang/haskell/README.org @@ -52,6 +52,11 @@ system package manager, cabal, or stack. formatters such as [[https://github.com/lspitzner/brittany][brittany]], [[https://github.com/ennocramer/floskell][floskell]], [[https://github.com/tweag/ormolu][ormolu]], [[https://github.com/fourmolu/fourmolu][fourmolu]], and [[https://github.com/haskell/stylish-haskell][stylish-haskell]], which can be installed through system package manager, cabal, or stack. +** Formatter + +[[doom-module::editor format]] by default uses [[https://github.com/fourmolu/fourmolu#installation][fourmolu]] to format code when not +relying on hls, follow the linked install instructions. + * TODO Usage #+begin_quote 🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]] @@ -61,12 +66,12 @@ This module integrates the haskell packages into Doom by providing things such as REPL support, project root recognition, etc. It also provide the following keybindings: -| Keybinding | Description | -|-----------------+-----------------------------------------------| -| [[kbd:][ b]] | Build the current cabal project | +| Keybinding | Description | +|-----------------+---------------------------------------------| +| [[kbd:][ b]] | Build the current cabal project | | [[kbd:][ c]] | Visit the =.cabal= file of the current buffer | -| [[kbd:][ h]] | Toggle visibility of the form at point | -| [[kbd:][ H]] | hides all top level functions | +| [[kbd:][ h]] | Toggle visibility of the form at point | +| [[kbd:][ H]] | hides all top level functions | * TODO Configuration #+begin_quote From 24bfd3f5b49e494731a8daef002b4973ce30b33d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 10:46:08 +0000 Subject: [PATCH 50/85] docs(java): add formatter docs --- modules/lang/java/README.org | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/lang/java/README.org b/modules/lang/java/README.org index 4f61fb98b..b0674681f 100644 --- a/modules/lang/java/README.org +++ b/modules/lang/java/README.org @@ -98,6 +98,18 @@ JAVA_HOME=~/.jabba/jdk/adopt@1.11.0-3 And then run ~$ direnv allow .~ in the project directory. The [[doom-module::tools direnv]] module will automatically source this environment before activating LSP servers. +** Formatter + +[[doom-module::editor format]] uses [[https://github.com/google/google-java-format][google-java-format]] to handle formatting. + +To install, grab the latest =all-deps.jar= release from the above, put it +somewhere and create a script similar to the below: + +=/usr/local/bin/google-java-format= +#+begin_src shell +java -jar /path/to/google-java-format-all-deps.jar +#+end_src + * TODO Usage #+begin_quote 🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]] From 39bbdde8c9c1f0c1e47b464cf29f62fc165663a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 10:47:44 +0000 Subject: [PATCH 51/85] docs(javascript): add formatter docs --- modules/lang/javascript/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/javascript/README.org b/modules/lang/javascript/README.org index a732c48a0..78b5c7cf6 100644 --- a/modules/lang/javascript/README.org +++ b/modules/lang/javascript/README.org @@ -58,6 +58,10 @@ This module requires [[https://nodejs.org/en/][NodeJS]] and one of [[https://www - Arch Linux: ~$ pacman --needed --noconfirm -S nodejs npm~ - openSUSE: ~$ zypper install nodejs npm~ +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://prettier.io/docs/en/install.html][prettier]]. + * TODO Usage #+begin_quote 🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]] From 65a62282a6708a249939df1a4f96d0bf0da48d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 10:48:34 +0000 Subject: [PATCH 52/85] docs(json): add formatter docs --- modules/lang/json/README.org | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/lang/json/README.org b/modules/lang/json/README.org index c3d6ed960..e60583e7d 100644 --- a/modules/lang/json/README.org +++ b/modules/lang/json/README.org @@ -32,7 +32,9 @@ This module adds [[https://www.json.org/json-en.html][JSON]] support to Doom Ema * Installation [[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]] -/This module has no external requirements./ +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://prettier.io/docs/en/install.html][prettier]]. * TODO Usage #+begin_quote From 311959ea1d47bc462d279b21ad3607a899d1ac8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 10:56:17 +0000 Subject: [PATCH 53/85] docs(kotlin): add install docs --- modules/lang/kotlin/README.org | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/lang/kotlin/README.org b/modules/lang/kotlin/README.org index 49e97a93e..003918c25 100644 --- a/modules/lang/kotlin/README.org +++ b/modules/lang/kotlin/README.org @@ -25,12 +25,22 @@ This module adds [[https://kotlinlang.org/][Kotlin]] support to Doom Emacs. # This section will be machine generated. Don't edit it by hand. /This module does not have a changelog yet./ -* TODO Installation +* Installation [[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]] -#+begin_quote - 🔨 /This module's prerequisites are not documented./ [[doom-contrib-module:][Document them?]] -#+end_quote +Install kotlin through your distribution's package manager, eg: + +#+begin_src shell +sudo apt install kotlin # Ubuntu +sudo pacman -S kotlin # Arch Linux +brew install kotlin # MacOS +#+end_src + +or by getting the [[https://github.com/JetBrains/kotlin/releases/latest][latest]] release and adding to your =$PATH= manually. + +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://pinterest.github.io/ktlint/install/cli/][ktlint]]. * TODO Usage #+begin_quote From 8410d9fe70a75471264db07e067ecddcf4cd46c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 14:22:26 +0000 Subject: [PATCH 54/85] docs(latex): add formatter docs --- modules/lang/latex/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/latex/README.org b/modules/lang/latex/README.org index 6ba4c5637..e718d15c3 100644 --- a/modules/lang/latex/README.org +++ b/modules/lang/latex/README.org @@ -93,6 +93,10 @@ brew install --cask mactex # WARNING: large 4gb download! environment.systemPackages = [ pkgs.texlive.combined.scheme-medium ]; #+end_src +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://github.com/cmhughes/latexindent.pl][latexindent]]. + * TODO Usage #+begin_quote 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] From 0577da300b2db82ad604520108a9b487cf972554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 14:26:54 +0000 Subject: [PATCH 55/85] docs(lua): add formatter docs --- modules/lang/lua/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/lua/README.org b/modules/lang/lua/README.org index 749f074e6..a3fe30bd0 100644 --- a/modules/lang/lua/README.org +++ b/modules/lang/lua/README.org @@ -75,6 +75,10 @@ Eglot currently only supports one of the above servers out of the box: =$EMACSDIR/.local/etc/lsp/lua-language-server/=. See ~+lua-lsp-dir~ variable to change this. +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://github.com/JohnnyMorganz/StyLua#installation][Stylua]]. + * TODO Usage #+begin_quote 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] From 51d3954c825aebc1bf5adb501904e083569e99a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 14:28:47 +0000 Subject: [PATCH 56/85] docs(markdown): add formatter docs --- modules/lang/markdown/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/markdown/README.org b/modules/lang/markdown/README.org index c07e06bae..675dd6852 100644 --- a/modules/lang/markdown/README.org +++ b/modules/lang/markdown/README.org @@ -115,6 +115,10 @@ installed through your OS's package manager: + MacOS: ~$ brew install multimarkdown~ + Arch Linux: [[https://aur.archlinux.org/packages/multimarkdown/][multimarkdown]] is available on the AUR +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://prettier.io/docs/en/install.html][prettier]]. + * TODO Usage #+begin_quote 🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]] From 9efadb5a420c9a2824f22aa3d9112e320cb49a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 14:31:53 +0000 Subject: [PATCH 57/85] docs(nim): add formatter docs --- modules/lang/nim/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/nim/README.org b/modules/lang/nim/README.org index b61d87eeb..805e2fa5b 100644 --- a/modules/lang/nim/README.org +++ b/modules/lang/nim/README.org @@ -51,6 +51,10 @@ Alternatively, nim is usually available through your OS's package manager: - Arch Linux: ~$ pacman --needed --noconfirm -S nim nimble~ - openSUSE: ~$ zypper install nim~ +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://github.com/FedericoCeratto/nimfmt#installation][nimfmt]]. + * TODO Usage #+begin_quote 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] From c86943f97bd684687d962c1db3ec626f4711a144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 14:42:35 +0000 Subject: [PATCH 58/85] docs(purescript): add install docs --- modules/lang/purescript/README.org | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/lang/purescript/README.org b/modules/lang/purescript/README.org index e109cb0a4..bb4c7c17b 100644 --- a/modules/lang/purescript/README.org +++ b/modules/lang/purescript/README.org @@ -26,12 +26,20 @@ This module adds [[https://www.purescript.org/][Purescript]] support to Doom Ema # This section will be machine generated. Don't edit it by hand. /This module does not have a changelog yet./ -* TODO Installation +* Installation [[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]] -#+begin_quote -🔨 /This module's prerequisites are not documented./ [[doom-contrib-module:][Document them?]] -#+end_quote +The main tools for PureScript are installed via npm. + +** Compiler +#+begin_src shell +npm install -g purescript spago +#+end_src + +** Formatter +#+begin_src sh +npm install -g purs-tidy +#+end_src * TODO Usage #+begin_quote From 601f9b0db61c88839d19eb262893f034057a49bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 14:44:57 +0000 Subject: [PATCH 59/85] docs(python): add formatter docs --- modules/lang/python/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/python/README.org b/modules/lang/python/README.org index 6d248d200..4a92accd0 100644 --- a/modules/lang/python/README.org +++ b/modules/lang/python/README.org @@ -92,6 +92,10 @@ An alternative LSP server can be used by installing them through the - To install *mspyls*: ~M-x lsp-install-server RET mspyls~. - To install *pyright*: ~$ pip install pyright~ or ~$ npm i -g pyright~. +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://black.readthedocs.io/en/stable/getting_started.html#installation][black]]. + * TODO Usage #+begin_quote 🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]] From 15f21fcb15b711d8fef271259816ed2528ab2abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 14:47:07 +0000 Subject: [PATCH 60/85] docs(racket): add formatter docs --- modules/lang/racket/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/racket/README.org b/modules/lang/racket/README.org index 46a406e00..ebc32bf51 100644 --- a/modules/lang/racket/README.org +++ b/modules/lang/racket/README.org @@ -43,6 +43,10 @@ Or, for fewer dependencies: pacman -S racket-minimal #+end_src +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://docs.racket-lang.org/fmt/][fmt]]. + * TODO Usage #+begin_quote 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] From 92ee29fec92daa2f88b0497168737a838325f334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 14:49:34 +0000 Subject: [PATCH 61/85] docs(rst): add formatter docs --- modules/lang/rst/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/rst/README.org b/modules/lang/rst/README.org index a019a62d4..87910e086 100644 --- a/modules/lang/rst/README.org +++ b/modules/lang/rst/README.org @@ -27,6 +27,10 @@ This module adds [[https://docutils.sourceforge.io/rst.html][ReStructured Text]] This module requires [[https://www.sphinx-doc.org/en/master/usage/installation.html][sphinx]] to build RST documents. +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://github.com/dzhu/rstfmt#usage][rstfmt]]. + * TODO Usage #+begin_quote 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] From 2e6ea90cf20b007d92d21eb6cbd898adc3a845aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 14:51:29 +0000 Subject: [PATCH 62/85] docs(ruby): add formatter docs --- modules/lang/ruby/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/ruby/README.org b/modules/lang/ruby/README.org index 137e651e6..0423ae36c 100644 --- a/modules/lang/ruby/README.org +++ b/modules/lang/ruby/README.org @@ -70,6 +70,10 @@ These guides will help you install Ruby: Then run ~$ gem install rubocop~ to install rubocop. +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://prettier.io/docs/en/install.html][prettier]]. + * TODO Usage #+begin_quote 🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]] From ee4a377cfa361ae7769ea2e3fea65fcf6bdfa259 Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Mon, 24 Jul 2023 19:47:49 +0100 Subject: [PATCH 63/85] docs(rust): update rustfmt command --- modules/lang/rust/README.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lang/rust/README.org b/modules/lang/rust/README.org index 3a7474bfe..7ff6833f9 100644 --- a/modules/lang/rust/README.org +++ b/modules/lang/rust/README.org @@ -64,7 +64,7 @@ To install and manage Rust on Windows, consult [[https://forge.rust-lang.org/inf ** Other Requirements - If [[doom-module::editor format]] is enabled, you'll need =rustfmt=: ~$ rustup component add - rustfmt-preview~. + rustfmt~. - Users with [[doom-module:+lsp]] enabled will need [[github:rust-analyzer/rust-analyzer][rust-analyzer]] (rls is supported, but [[https://blog.rust-lang.org/2022/07/01/RLS-deprecation.html][deprecated]]). - Using the following commands requires: From a7e8ee691006b7d6808b23f1b5d2429f2e554d54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 14:59:02 +0000 Subject: [PATCH 64/85] docs(scala): add formatter docs --- modules/lang/scala/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/scala/README.org b/modules/lang/scala/README.org index 813fe83ea..af9ebd1fc 100644 --- a/modules/lang/scala/README.org +++ b/modules/lang/scala/README.org @@ -95,6 +95,10 @@ coursier bootstrap \ yay -S metals #+end_src +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://scalameta.org/scalafmt/docs/installation.html#cli][scalafmt]]. + * TODO Usage #+begin_quote 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] From fa145f5cc15405204b7c214f2f1539377aa68050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 15:11:58 +0000 Subject: [PATCH 65/85] docs(sh): add formatter docs --- modules/lang/sh/README.org | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/lang/sh/README.org b/modules/lang/sh/README.org index 6cd1c5a79..dc19a57c9 100644 --- a/modules/lang/sh/README.org +++ b/modules/lang/sh/README.org @@ -49,6 +49,8 @@ This module has several optional dependencies: - With the [[doom-module::tools debugger]] module - [[http://bashdb.sourceforge.net/][bashdb]]: Enables debugging for bash scripts - [[https://github.com/rocky/zshdb][zshdb]]: Enables debugging for zsh scripts +- With the [[doom-module::editor format]] module + - [[https://github.com/patrickvane/shfmt][shfmt]]: Enables formatting for {posix,ba,mk}sh scripts * TODO Usage #+begin_quote From 308ab45300ce7c5c861ad246aa43092b221ad963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 15:13:32 +0000 Subject: [PATCH 66/85] docs(sml): add formatter docs --- modules/lang/sml/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/sml/README.org b/modules/lang/sml/README.org index 150043776..48962c5aa 100644 --- a/modules/lang/sml/README.org +++ b/modules/lang/sml/README.org @@ -28,6 +28,10 @@ THis module adds [[https://smlfamily.github.io/][SML (Standard ML) programming l This module requires =sml= and =MLton=. +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://github.com/jluningp/smlformat#installation][smlformat]]. + * TODO Usage #+begin_quote 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] From 580ec33d3a6bf518ae32553287a7a1554de6d8cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 15:15:37 +0000 Subject: [PATCH 67/85] feat(sml): add :lang sml formatter --- modules/lang/solidity/config.el | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/lang/solidity/config.el b/modules/lang/solidity/config.el index d53d8ca3d..330333f9d 100644 --- a/modules/lang/solidity/config.el +++ b/modules/lang/solidity/config.el @@ -7,6 +7,7 @@ (setq solidity-comment-style 'slash) (set-docsets! 'solidity-mode "Solidity") (set-company-backend! 'solidity-mode 'company-solidity) + (set-formatter! 'prettier-solidity '(npx "prettier" "--stdin-filepath" filepath "--parser=solidity") :modes '(solidity-mode)) (use-package! solidity-flycheck ; included with solidity-mode :when (and (modulep! :checkers syntax) From 076c6d9183575c51511d536bc4a91e1c2e61246d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 15:15:57 +0000 Subject: [PATCH 68/85] docs(solidity): add formatter docs --- modules/lang/solidity/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/solidity/README.org b/modules/lang/solidity/README.org index 3a66e940a..5e6a7c023 100644 --- a/modules/lang/solidity/README.org +++ b/modules/lang/solidity/README.org @@ -55,6 +55,10 @@ can set it to your own =.soliumrc.json= with: (setq flycheck-solidity-solium-soliumrcfile "~/.soliumrc.json") #+end_src +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://github.com/prettier-solidity/prettier-plugin-solidity#installation-and-usage][prettier]]. + * TODO Usage #+begin_quote 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] From 4a55ac843c6b966d60a0267db91d1c5c444782da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 15:21:08 +0000 Subject: [PATCH 69/85] docs(swift): add formatter docs --- modules/lang/swift/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/swift/README.org b/modules/lang/swift/README.org index 380ae1165..b3606f378 100644 --- a/modules/lang/swift/README.org +++ b/modules/lang/swift/README.org @@ -35,6 +35,10 @@ This module adds support for the [[https://developer.apple.com/swift/][Swift pro * TODO Installation [[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]] +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://github.com/nicklockwood/SwiftFormat#command-line-tool][swiftformat]]. + #+begin_quote 🔨 /This module's prerequisites are not documented./ [[doom-contrib-module:][Document them?]] #+end_quote From 953cfd342b82320fd05fae8ca5e6ee8d3e31366c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 15:24:18 +0000 Subject: [PATCH 70/85] docs(web): add formatter docs --- modules/lang/web/README.org | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/lang/web/README.org b/modules/lang/web/README.org index b24116eed..b6ad7c7c5 100644 --- a/modules/lang/web/README.org +++ b/modules/lang/web/README.org @@ -48,6 +48,10 @@ ReactJS, Wordpress, Jekyll, Phaser, AngularJS, Djano, and more. * TODO Installation [[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]] +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://prettier.io/docs/en/install.html][prettier]]. + #+begin_quote 🔨 /No installation steps have been documented./ [[doom-contrib-module:][Document them?]] #+end_quote From 679d0d00932358eb62065ff08b3c516cdbce88a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 15:26:03 +0000 Subject: [PATCH 71/85] docs(docker): add formatter docs --- modules/tools/docker/README.org | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/tools/docker/README.org b/modules/tools/docker/README.org index 07596c85c..e6bb483de 100644 --- a/modules/tools/docker/README.org +++ b/modules/tools/docker/README.org @@ -40,6 +40,7 @@ installed and accessible from your PATH. Optionally, this module also uses the following programs: - =docker-langserver= (for LSP users): ~$ npm install -g dockerfile-language-server-nodejs~ +- =dockfmt= for [[doom-module::editor format]]: https://github.com/jessfraz/dockfmt#installation * TODO Usage #+begin_quote From e852bbcf6cd01b29d7e4c00280daec70aca42d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 15:44:56 +0000 Subject: [PATCH 72/85] docs(yaml): add formatter docs --- modules/lang/yaml/README.org | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/lang/yaml/README.org b/modules/lang/yaml/README.org index dd87f1fd0..7137f7067 100644 --- a/modules/lang/yaml/README.org +++ b/modules/lang/yaml/README.org @@ -30,7 +30,9 @@ This module provides support for the [[https://yaml.org/][YAML file format]] to * Installation [[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]] -/This module has no external requirements./ +** Formatter + +Formatting is handled using the [[doom-module::editor format]] module via [[https://prettier.io/docs/en/install.html][prettier]]. * TODO Usage #+begin_quote From 457aeeccc0b6ba5d15711e1079c2accb45cdf114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 16:41:16 +0000 Subject: [PATCH 73/85] fix(format): better handle format-on-save disable --- modules/editor/format/config.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 94aa46dba..9610e1154 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -1,5 +1,17 @@ ;;; editor/format/config.el -*- lexical-binding: t; -*- +(defvar +format-on-save-disabled-modes + '(sql-mode ; sqlformat is currently broken + tex-mode ; latexindent is broken + latex-mode + org-msg-edit-mode) ; doesn't need a formatter + "A list of major modes in which to reformat the buffer upon saving. +If this list begins with `not', then it negates the list. +If it is `t', it is enabled in all modes. +If nil, it is disabled in all modes, the same as if the +onsave flag wasn't + used at all. +Irrelevant if you do not have the +onsave flag enabled for this module.") + (defvar +format-preserve-indentation t "If non-nil, the leading indentation is preserved when formatting the whole buffer. This is particularly useful for partials. @@ -22,6 +34,15 @@ select buffers.") (when (modulep! +onsave) (add-hook 'doom-first-file-hook #'apheleia-global-mode)) +(defun +format-enable-on-save-maybe-h () + "Enable formatting on save in certain major modes. +This is controlled by `+format-on-save-disabled-modes'." + (setq-local apheleia-inhibit (or (eq major-mode 'fundamental-mode) + (string-empty-p (string-trim (buffer-name))) + (not (null (memq major-mode +format-on-save-disabled-modes)))))) + +(when (modulep! +onsave) + (add-hook 'after-change-major-mode-hook #'+format-enable-on-save-maybe-h)) ;; ;;; Hacks From 926b8f132862dbcbc0a23c77765180d2a75bbc61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ellis=20Keny=C5=91?= Date: Sat, 19 Nov 2022 16:43:31 +0000 Subject: [PATCH 74/85] docs(format): redo docs to handle refactor --- modules/editor/format/README.org | 195 +++++++++++++------------------ 1 file changed, 80 insertions(+), 115 deletions(-) diff --git a/modules/editor/format/README.org b/modules/editor/format/README.org index dd23f3988..bb38e23a7 100644 --- a/modules/editor/format/README.org +++ b/modules/editor/format/README.org @@ -3,44 +3,37 @@ #+created: July 26, 2020 #+since: 21.12.0 -#+begin_quote - 🔨 This module has been scheduled for a rewrite. Its documentation will remain - incomplete and edge cases left unpatched in the meantime. A preview of this - rewrite can be found [[https://github.com/hlissner/doom-emacs-private/tree/master/modules/editor/format][in my private config]]. -#+end_quote - * Description :unfold: -This module integrates code formatters into Emacs. Here are some of the -formatters that it currently supports: +Code style is something that's hotly debated since the beginning of time. -#+begin_quote -asmfmt, black, brittany, cabal-fmt, clang-format, cmake-format, dartfmt, dfmt, -dhall format, dockfmt, elm-format, emacs, fish_indent, fprettify, gleam format, -gofmt, iStyle, jsonnetfmt, ktlint, latexindent, ledger-mode, lua-fmt, mix -format, nixfmt, node-cljfmt, ocp-indent, perltidy, prettier, purty, rufo, -rustfmt, scalafmt, script shfmt, snakefmt, sqlformat, styler, swiftformat, tidy -#+end_quote +Tabs or spaces? +2-width or 4-width indentation? + +Which is right? Doom doesn't care, but we will try and make it easy for you to +format code within the safety of Emacs. + +At present, the module wraps [[https://github.com/radian-software/apheleia/][apheleia]], which includes some more detail on the +internals of the package; but the long and short of it is on-save your code will +be formatted and returned to the buffer using +[[https://tools.ietf.org/doc/tcllib/html/rcs.html#section4][RCS patching]]. ** Maintainers -/This module has no dedicated maintainers./ [[doom-contrib-maintainer:][Become a maintainer?]] +- [[doom-user:][@elken]] + +[[doom-contrib-maintainer:][Become a maintainer?]] ** Module flags - +onsave :: Enable reformatting of a buffer when it is saved. See - [[var:+format-on-save-enabled-modes]] to control what major modes to (or not to) + [[var:+format-on-save-disabled-modes]] to control what major modes to (or not to) format on save. ** Packages -- [[doom-package:format-all]] +- [[doom-package:apheleia]] ** Hacks -- format-all has been heavily modified to suit Doom's goals for this module: - - Reformatted text is applied to the buffer by RCS patch, as to reduce its - affect on cursor position. - - Adds partial formatting, i.e. you can now reformat a subset of the buffer. - - Adds the ability to use any arbitrary formatter on the current buffer if you - pass the universal argument to [[fn:+format/buffer]] or [[fn:+format/region]] (i.e. - removes the major-mode lock on formatters). +As of writing this, apheleia doesn't /yet/ support regions or similar kinds of +buffers, so there are a couple of hacks to attempt to rectify this. ** TODO Changelog # This section will be machine generated. Don't edit it by hand. @@ -51,98 +44,64 @@ rustfmt, scalafmt, script shfmt, snakefmt, sqlformat, styler, swiftformat, tidy This module has no direct requirements, but each language will need one of their supported formatter programs in order for this to work. In their absence, -[[doom-package:format-all]] will fail silently. +[[doom-package:apheleia]] will fail silently. -Supported formatters: -- Angular/Vue (prettier) -- Assembly (asmfmt) -- Bazel Starlark (buildifier) -- BibTeX (emacs) -- C/C++/Objective-C (clang-format) -- Cabal (cabal-fmt) -- Clojure/ClojureScript (node-cljfmt) -- CMake (cmake-format) -- Crystal (crystal tool format) -- CSS/Less/SCSS (prettier) -- D (dfmt) -- Dart (dartfmt) -- Dhall (dhall format) -- Dockerfile (dockfmt) -- Elixir (mix format) -- Elm (elm-format) -- Emacs Lisp (emacs) -- Fish Shell (fish_indent) -- Fortran 90 (fprettify) -- Gleam (gleam format) -- Go (gofmt) -- GraphQL (prettier) -- Haskell (brittany) -- HTML/XHTML/XML (tidy) -- Java (clang-format) -- JavaScript/JSON/JSX (prettier) -- Jsonnet (jsonnetfmt) -- Kotlin (ktlint) -- LaTeX (latexindent) -- Ledger (ledger-mode) -- Lua (lua-fmt) -- Markdown (prettier) -- Nix (nixfmt) -- OCaml (ocp-indent) -- Perl (perltidy) -- PHP (prettier plugin-php) -- Protocol Buffers (clang-format) -- PureScript (purty) -- Python (black) -- R (styler) -- Ruby (rufo) -- Rust (rustfmt) -- Scala (scalafmt) -- Shell script (shfmt) -- Snakemake (snakefmt) -- Solidity (prettier-plugin-solidity) -- SQL (sqlformat) -- Swift (swiftformat) -- Terraform (terraform fmt) -- TOML (prettier-plugin-toml) -- TypeScript/TSX (prettier) -- Verilog (iStyle) -- YAML (prettier) +To see if a particular mode has a configured formatter, check for the mode in +[[var:apheleia-mode-alist]] which corresponds to the list of formatters defined in +[[var:apheleia-formatters]] -* TODO Usage -#+begin_quote - 🔨 This module has no usage documentation yet. [[doom-contrib-module:][Write some?]] -#+end_quote +* Usage +** With +onsave +When this flag is enabled, you shouldn't need to do anything other than write +code and save it. -* TODO Configuration -#+begin_quote - 🔨 /This module's configuration documentation is incomplete./ [[doom-contrib-module:][Complete it?]] -#+end_quote +** Without +onsave +Without the flag, formatting will only occur when either =apheleia-format-buffer= +or =+format/buffer= is called. -** Automatic reformatting when saving buffers -There are two ways to achieve this. Either through the =+onsave= flag, or by -adding ~format-all-mode~ to the hook of each major mode you want this behavior -enabled in. +* Configuration + +Detailed configuration can be found [[https://github.com/radian-software/apheleia/#user-guide][upstream]], but for most purposes here we +provide a simple macro that looks like the below: -If you choose the former, what modes it applies to can be changed by modifying -~+format-on-save-enabled-modes~, which contains a list of major modes. If the -first item in the list is the symbol ~not~, the list is negated. This is its -default value: #+begin_src emacs-lisp -(setq +format-on-save-enabled-modes - '(not emacs-lisp-mode ; elisp's mechanisms are good enough - sql-mode ; sqlformat is currently broken - tex-mode ; latexindent is broken - latex-mode)) +(set-formatter! 'unique-name '("command" "line" "here") :modes '(name-of-major-mode)) #+end_src -If you want to format code when you save a buffer, but want more granular -control over which major modes this behavior is enabled in, there is an -alternative. Make sure [[doom-module:+onsave]] is disabled before you try this: +There are a few bonus symbols that apheleia uses (for example =npx= will be +replaced by a correct path to npx) which are all documented in the link above. + +** Disabling formatters +*** Permanently +To permanently disable a particular formatter with no provided alternative + #+begin_src emacs-lisp -(add-hook 'python-mode-hook #'format-all-mode) -(add-hook 'js2-mode-hook #'format-all-mode) +(setq apheleia-formatters (delq (assoc 'csharpier apheleia-formatters) apheleia-formatters)) #+end_src +*** Per-buffer +If you want to save without formatting, this is done by first passing the +universal argument thus; =SPC u SPC f s= for evil users, =C-u C-x C-s= for non-evil +users. + +If you want to save more than a handful of time, you can set +[[var:apheleia-inhibit]] to disable even if =apheleia-global-mode= is on. + +*** Onsave only +This behaviour is controlled via [[var:+format-on-save-disabled-modes]] thus; + +#+begin_src emacs-lisp +(setq +format-on-save-disabled-modes + '(emacs-lisp-mode ; elisp's mechanisms are good enough + sql-mode ; sqlformat is currently broken + tex-mode ; latexindent is broken + latex-mode)) +#+end_src + +In this case, =emacs-lisp-mode=, =sql-mode=, =tex-mode= and =latex-mode= will not be +formatted on save, but can still be formatted by manually invoking the commands +=apheleia-format-buffer= or =+format/buffer=. + ** Disabling the LSP formatter If you are in a buffer with ~lsp-mode~ enabled and a server that supports =textDocument/formatting=, it will be used instead of [[doom-package:format-all]]'s formatter. @@ -151,25 +110,31 @@ If you are in a buffer with ~lsp-mode~ enabled and a server that supports + To disable this behavior in one mode: ~(setq-hook! 'python-mode-hook +format-with-lsp nil)~ -** TODO Defining your own formatters -See the ~set-formatter!~ function. - -** TODO Selecting a specific formatter for a particular buffer +** Selecting a specific formatter for a particular buffer Set the buffer-local variable ~+format-with~ to the name of the formatter to use. e.g. #+begin_src emacs-lisp +;; Overrides `apheleia-mode-alist` (setq-hook! 'python-mode-hook +format-with 'html-tidy) -;; Or set it to `:none' to disable formatting -(setq-hook! 'python-mode-hook +format-with :none) +;; Or set it to `nil' to fallback to `apheleia-mode-alist` +(setq-hook! 'python-mode-hook +format-with nil) #+end_src Formatters are referred to by the name they were defined with. They can be -looked up in the ~format-all-mode-table~ hash table or in format-all's [[https://github.com/lassik/emacs-format-all-the-code/blob/master/format-all.el#L512][source -code]]. +looked up in the ~apheleia-mode-alist~ hash table. * Troubleshooting -/There are no known problems with this module./ [[doom-report:][Report one?]] +There are a few fail-safes apheleia has to prevent accidental code wipe, +included silently failing if the command errors or doesn't exist. + +Check that the command you've specified runs fine in a terminal first before +reporting this as an issue. + +If any errors are reported from the command, run =apheleia-goto-error= to jump to +the error buffer and handle any problems raised there. + +Any issues specific to apheleia should most often be reported upstream [[https://github.com/radian-software/apheleia/issues][here]]. * Frequently asked questions /This module has no FAQs yet./ [[doom-suggest-faq:][Ask one?]] From b34533de968f1b468b193b7c1e52ad5968588d63 Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Sat, 3 Dec 2022 09:37:45 +0000 Subject: [PATCH 75/85] fix(format): load format-on-save-disabled-modes fn Should handle some corner cases with how inhibiting is set --- modules/editor/format/config.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 9610e1154..28f7dc17e 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -34,15 +34,15 @@ select buffers.") (when (modulep! +onsave) (add-hook 'doom-first-file-hook #'apheleia-global-mode)) -(defun +format-enable-on-save-maybe-h () +(defun +format-inhibit-maybe-h () "Enable formatting on save in certain major modes. This is controlled by `+format-on-save-disabled-modes'." - (setq-local apheleia-inhibit (or (eq major-mode 'fundamental-mode) - (string-empty-p (string-trim (buffer-name))) - (not (null (memq major-mode +format-on-save-disabled-modes)))))) + (or (eq major-mode 'fundamental-mode) + (string-empty-p (string-trim (buffer-name))) + (not (null (memq major-mode +format-on-save-disabled-modes))))) (when (modulep! +onsave) - (add-hook 'after-change-major-mode-hook #'+format-enable-on-save-maybe-h)) + (add-to-list 'apheleia-inhibit-functions #'+format-inhibit-maybe-h)) ;; ;;; Hacks From 550767efe2fecda7bfd11fea5c6ff9e889f44dff Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Sun, 8 Jan 2023 15:20:12 +0000 Subject: [PATCH 76/85] fix(format): apheleia-inhibit-functions after load --- modules/editor/format/config.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 28f7dc17e..3883c16ab 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -41,8 +41,9 @@ This is controlled by `+format-on-save-disabled-modes'." (string-empty-p (string-trim (buffer-name))) (not (null (memq major-mode +format-on-save-disabled-modes))))) -(when (modulep! +onsave) - (add-to-list 'apheleia-inhibit-functions #'+format-inhibit-maybe-h)) +(after! apheleia + (when (modulep! +onsave) + (add-to-list 'apheleia-inhibit-functions #'+format-inhibit-maybe-h))) ;; ;;; Hacks From b0e579741e7ea16635b8725bca419a1a264dd281 Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Fri, 14 Apr 2023 21:11:34 +0100 Subject: [PATCH 77/85] fix(format): react to ns change --- modules/editor/format/autoload/settings.el | 2 +- modules/editor/format/config.el | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/editor/format/autoload/settings.el b/modules/editor/format/autoload/settings.el index 85c71d354..575f008d8 100644 --- a/modules/editor/format/autoload/settings.el +++ b/modules/editor/format/autoload/settings.el @@ -71,7 +71,7 @@ Advanced examples: " (declare (indent defun)) (cl-check-type name symbol) - (after! apheleia + (after! apheleia-core (if (null args) (progn (setq apheleia-formatters diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 3883c16ab..5d4b0f5ab 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -41,7 +41,7 @@ This is controlled by `+format-on-save-disabled-modes'." (string-empty-p (string-trim (buffer-name))) (not (null (memq major-mode +format-on-save-disabled-modes))))) -(after! apheleia +(after! apheleia-core (when (modulep! +onsave) (add-to-list 'apheleia-inhibit-functions #'+format-inhibit-maybe-h))) @@ -70,7 +70,7 @@ This is controlled by `+format-on-save-disabled-modes'." ;; ;;; Additional formatters -(after! apheleia +(after! apheleia-core ;; TODO html-tidy (cl-defun apheleia--indent-lisp-buffer (&key buffer scratch callback &allow-other-keys) From 12d520a3771ec509fa1e83499aa86d114e4619ed Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Thu, 4 May 2023 08:59:42 +0100 Subject: [PATCH 78/85] fix(format): remove merged formatter --- modules/editor/format/config.el | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 5d4b0f5ab..0773c8765 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -65,26 +65,3 @@ This is controlled by `+format-on-save-disabled-modes'." (font-lock-fontify-region web-mode-scan-beg web-mode-scan-end))))) (defun +format--refresh-git-gutter-h () (+vc-gutter-init-maybe-h))) - - -;; -;;; Additional formatters - -(after! apheleia-core - ;; TODO html-tidy - (cl-defun apheleia--indent-lisp-buffer - (&key buffer scratch callback &allow-other-keys) - "Format a Lisp BUFFER. Use SCRATCH as a temporary buffer and CALLBACK to -apply the transformation. For more implementation detail, see -`apheleia--run-formatter-function'." - (with-current-buffer scratch - (setq-local indent-line-function - (buffer-local-value 'indent-line-function buffer)) - (setq-local lisp-indent-function - (buffer-local-value 'lisp-indent-function buffer)) - (funcall (with-current-buffer buffer major-mode)) - (goto-char (point-min)) - (let ((inhibit-message t) - (message-log-max nil)) - (indent-region (point-min) (point-max))) - (funcall callback)))) From 249a39acb49e65e32a424e7ffeba69b3174394a4 Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Mon, 24 Jul 2023 19:42:29 +0100 Subject: [PATCH 79/85] fix(format): pin apheleia --- modules/editor/format/packages.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/editor/format/packages.el b/modules/editor/format/packages.el index 0f1fd9933..17a308621 100644 --- a/modules/editor/format/packages.el +++ b/modules/editor/format/packages.el @@ -1,5 +1,4 @@ ;; -*- no-byte-compile: t; -*- ;;; editor/format/packages.el -;; TODO Pin when this is close to finish -(package! apheleia) +(package! apheleia :pin "c222927f7086d407dad01b2609ff68768e9adddb") From 79172239a711f6af8ae9ebd30c632ca7a335b0ed Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Mon, 24 Jul 2023 20:53:18 +0100 Subject: [PATCH 80/85] fix(clojure): prefer cljfmt now it supports STDIN --- modules/lang/clojure/config.el | 4 ++-- modules/lang/clojure/doctor.el | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/lang/clojure/config.el b/modules/lang/clojure/config.el index 025d372a6..a9c7761e2 100644 --- a/modules/lang/clojure/config.el +++ b/modules/lang/clojure/config.el @@ -16,8 +16,8 @@ (use-package! clojure-mode :hook (clojure-mode . rainbow-delimiters-mode) :config - (when (executable-find "zprint") - (set-formatter! 'zprint '("zprint") :modes '(clojure-mode clojurec-mode clojurescript-mode))) + (when (executable-find "cljfmt") + (set-formatter! 'cljfmt '("cljfmt" "fix" "-") :modes '(clojure-mode clojurec-mode clojurescript-mode))) (when (modulep! +lsp) (add-hook! '(clojure-mode-local-vars-hook diff --git a/modules/lang/clojure/doctor.el b/modules/lang/clojure/doctor.el index 529c3ba4b..5cc63fb90 100644 --- a/modules/lang/clojure/doctor.el +++ b/modules/lang/clojure/doctor.el @@ -7,5 +7,5 @@ (warn! "Couldn't find clj-kondo. flycheck-clj-kondo will not work."))) (when (modulep! :editor format) - (unless (executable-find "zprint") - (warn! "Couldn't find zprint. Formatting will be disabled."))) + (unless (executable-find "cljfmt") + (warn! "Couldn't find cljfmt. Formatting will be disabled."))) From bc58da7c78eef3b4a38743724337c22fa831eb14 Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Wed, 13 Sep 2023 10:10:30 +0100 Subject: [PATCH 81/85] fix(zig): correct doctor check --- modules/lang/zig/doctor.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lang/zig/doctor.el b/modules/lang/zig/doctor.el index 38b1bec3a..48668cef3 100644 --- a/modules/lang/zig/doctor.el +++ b/modules/lang/zig/doctor.el @@ -12,7 +12,7 @@ (unless (executable-find "zig") (warn! "Couldn't find zig binary") - (when (modulep! :editor format) + (unless (modulep! :editor format) (warn! "Formatting will be disabled"))) (when (modulep! +lsp) From f67f3914433d613e16442e76b7407c4fe9a4ea09 Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Wed, 13 Sep 2023 10:16:26 +0100 Subject: [PATCH 82/85] fix(common-lisp): amend sly-compat hook --- modules/lang/common-lisp/config.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/lang/common-lisp/config.el b/modules/lang/common-lisp/config.el index 07ab50c5b..9edc7f548 100644 --- a/modules/lang/common-lisp/config.el +++ b/modules/lang/common-lisp/config.el @@ -31,8 +31,8 @@ :definition #'sly-edit-definition :documentation #'sly-describe-symbol)) - (add-hook! 'lisp-mode - (after! sly (sly-lisp-indent-compatibility-mode))) + ;; This needs to be appended so it fires later than `sly-editing-mode' + (add-hook 'lisp-mode-local-vars-hook #'sly-lisp-indent-compatibility-mode 'append) ;; HACK Ensures that sly's contrib modules are loaded as soon as possible, but ;; also as late as possible, so users have an opportunity to override From 23a39b0a14d8fa15ecba0e1d2d4d732c49480d0b Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Wed, 13 Sep 2023 10:17:23 +0100 Subject: [PATCH 83/85] fix(clojure): remove executable-find formatter check --- modules/lang/clojure/config.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/lang/clojure/config.el b/modules/lang/clojure/config.el index a9c7761e2..a552ba2f2 100644 --- a/modules/lang/clojure/config.el +++ b/modules/lang/clojure/config.el @@ -16,8 +16,7 @@ (use-package! clojure-mode :hook (clojure-mode . rainbow-delimiters-mode) :config - (when (executable-find "cljfmt") - (set-formatter! 'cljfmt '("cljfmt" "fix" "-") :modes '(clojure-mode clojurec-mode clojurescript-mode))) + (set-formatter! 'cljfmt '("cljfmt" "fix" "-") :modes '(clojure-mode clojurec-mode clojurescript-mode)) (when (modulep! +lsp) (add-hook! '(clojure-mode-local-vars-hook From ce93f899fd0ec069cb1fa43c9c8841991785e524 Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Wed, 13 Sep 2023 10:19:39 +0100 Subject: [PATCH 84/85] fix(format): improve function/module loading safety --- modules/editor/format/config.el | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/modules/editor/format/config.el b/modules/editor/format/config.el index 0773c8765..f9c63db1f 100644 --- a/modules/editor/format/config.el +++ b/modules/editor/format/config.el @@ -41,8 +41,9 @@ This is controlled by `+format-on-save-disabled-modes'." (string-empty-p (string-trim (buffer-name))) (not (null (memq major-mode +format-on-save-disabled-modes))))) -(after! apheleia-core - (when (modulep! +onsave) + +(when (modulep! +onsave) + (after! apheleia-core (add-to-list 'apheleia-inhibit-functions #'+format-inhibit-maybe-h))) ;; @@ -54,14 +55,17 @@ This is controlled by `+format-on-save-disabled-modes'." (let ((apheleia-mode (and apheleia-mode (member arg '(nil 1))))) (funcall orig-fn))) -(add-hook! 'apheleia-post-format-hook - ;; HACK `web-mode' doesn't update syntax highlighting after arbitrary buffer - ;; modifications, so we must trigger refontification manually. - (defun +format--fix-web-mode-fontification-h () - (when (eq major-mode 'web-mode) - (setq web-mode-fontification-off nil) - (when (and web-mode-scan-beg web-mode-scan-end global-font-lock-mode) - (save-excursion - (font-lock-fontify-region web-mode-scan-beg web-mode-scan-end))))) - (defun +format--refresh-git-gutter-h () - (+vc-gutter-init-maybe-h))) +(add-hook! + 'apheleia-post-format-hook + ;; HACK `web-mode' doesn't update syntax highlighting after arbitrary buffer + ;; modifications, so we must trigger refontification manually. + (defun +format--fix-web-mode-fontification-h () + (when (eq major-mode 'web-mode) + (setq web-mode-fontification-off nil) + (when (and web-mode-scan-beg web-mode-scan-end global-font-lock-mode) + (save-excursion + (font-lock-fontify-region web-mode-scan-beg web-mode-scan-end))))) + + (defun +format--refresh-git-gutter-h () + (when (fboundp '+vc-gutter-update-h) + (+vc-gutter-init-maybe-h)))) From dd68bbb7da530bd99e2bce77a41d4f01b6db119c Mon Sep 17 00:00:00 2001 From: Ellis Kenyo Date: Wed, 13 Sep 2023 10:20:39 +0100 Subject: [PATCH 85/85] fix(format): removed unused argument --- modules/editor/format/autoload/settings.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/editor/format/autoload/settings.el b/modules/editor/format/autoload/settings.el index 575f008d8..f52a41e12 100644 --- a/modules/editor/format/autoload/settings.el +++ b/modules/editor/format/autoload/settings.el @@ -1,7 +1,7 @@ ;;; editor/format/autoload/settings.el -*- lexical-binding: t; -*- ;;;###autodef -(cl-defun set-formatter! (name args &key modes filter) +(cl-defun set-formatter! (name args &key modes) "Define (or modify) a formatter named NAME. Supported keywords: :modes :filter