From 55bddd1fa06cd9848a4934c7b4caa935fffe0f56 Mon Sep 17 00:00:00 2001 From: Bastien Date: Sun, 1 Oct 2017 11:06:35 +0200 Subject: [PATCH 1/2] clojure-mode.el (clojure-mode): Force electric indentation in a docstring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default, ‘electric-layout-post-self-insert-function’ prevents indentation in strings and comments. When ‘electric-indent-mode’ is on, we want ‘newline’ to reindent the line when the point is within a docstring, so this patch adds a hook to ‘electric-indent-functions’ to that effect. --- clojure-mode.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clojure-mode.el b/clojure-mode.el index 8ed7f5f9..32810054 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -524,7 +524,9 @@ replacement for `cljr-expand-let`." \\{clojure-mode-map}" (clojure-mode-variables) (clojure-font-lock-setup) - (add-hook 'paredit-mode-hook #'clojure-paredit-setup)) + (add-hook 'paredit-mode-hook #'clojure-paredit-setup) + (add-hook 'electric-indent-functions + (lambda (c) (if (clojure-in-docstring-p) 'do-indent)))) (defcustom clojure-verify-major-mode t "If non-nil, warn when activating the wrong `major-mode'." From db72aea777c09e8cb319307f91548fa902dee9da Mon Sep 17 00:00:00 2001 From: Bastien Date: Sat, 7 Oct 2017 23:41:01 +0200 Subject: [PATCH 2/2] Complete previous commit --- CHANGELOG.md | 1 + clojure-mode.el | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da1a6d9d..d7b50898 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Bugs fixed +* [#447](https://github.com/clojure-emacs/clojure-mode/issues/241): When `electric-indent-mode` is on, force indentation from within docstrings. * [#438](https://github.com/clojure-emacs/clojure-mode/issues/438): Filling within a doc-string doesn't affect surrounding code. * Fix fill-paragraph in multi-line comments. * [#443](https://github.com/clojure-emacs/clojure-mode/issues/443): Fix behavior of `clojure-forward-logical-sexp` and `clojure-backward-logical-sexp` with conditional macros. diff --git a/clojure-mode.el b/clojure-mode.el index 32810054..711bc933 100644 --- a/clojure-mode.el +++ b/clojure-mode.el @@ -525,8 +525,10 @@ replacement for `cljr-expand-let`." (clojure-mode-variables) (clojure-font-lock-setup) (add-hook 'paredit-mode-hook #'clojure-paredit-setup) + ;; `electric-layout-post-self-insert-function' prevents indentation in strings + ;; and comments, force indentation in docstrings: (add-hook 'electric-indent-functions - (lambda (c) (if (clojure-in-docstring-p) 'do-indent)))) + (lambda (char) (if (clojure-in-docstring-p) 'do-indent)))) (defcustom clojure-verify-major-mode t "If non-nil, warn when activating the wrong `major-mode'."