[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/crux 6d11d2e 039/112: When opening a line above, don't rei
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/crux 6d11d2e 039/112: When opening a line above, don't reindent the current line |
Date: |
Wed, 11 Aug 2021 09:57:49 -0400 (EDT) |
branch: elpa/crux
commit 6d11d2e6b56e237bb871af7e21ba6ef30e0a10da
Author: Wilfred Hughes <me@wilfred.me.uk>
Commit: Bozhidar Batsov <bozhidar.batsov@gmail.com>
When opening a line above, don't reindent the current line
For some languages, we can't call `indent-according-to-mode` as there
are multiple possible indentations. Python is a great example. For these
languages, `electric-indent-inhibit` is `t` to prevent emacs changing
indentation without the user requesting it.
In this situation, we give the new line the same indentation characters as
the
current line. This ensures we respect the user's tab/space configuration.
Closes #26.
---
crux.el | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/crux.el b/crux.el
index a0a9cb8..e88bc0c 100644
--- a/crux.el
+++ b/crux.el
@@ -136,12 +136,24 @@ the current buffer."
(defun crux-smart-open-line-above ()
"Insert an empty line above the current line.
-Position the cursor at it's beginning, according to the current mode."
+Position the cursor at its beginning, according to the current mode."
(interactive)
(move-beginning-of-line nil)
- (newline-and-indent)
- (forward-line -1)
- (indent-according-to-mode))
+ (insert "\n")
+ (if electric-indent-inhibit
+ ;; We can't use `indent-according-to-mode' in languages like Python,
+ ;; as there are multiple possible indentations with different meanings.
+ (let* ((indent-end (progn (back-to-indentation) (point)))
+ (indent-start (progn (move-beginning-of-line nil) (point)))
+ (indent-chars (buffer-substring indent-start indent-end)))
+ (forward-line -1)
+ ;; This new line should be indented with the same characters as
+ ;; the current line.
+ (insert indent-chars))
+ ;; Just use the current major-mode's indent facility.
+ (progn
+ (forward-line -1)
+ (indent-according-to-mode))))
(defun crux-smart-open-line (arg)
"Insert an empty line after the current line.
- [nongnu] elpa/crux e6e3221 025/112: Fix crux-*-file-and-buffer commands inconsistencies and alias the inverse, (continued)
- [nongnu] elpa/crux e6e3221 025/112: Fix crux-*-file-and-buffer commands inconsistencies and alias the inverse, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 4c90762 026/112: Add complementary `with-region-or-line` & `with-region-or-point-to-eol`, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e4c539b 028/112: Merge pull request #9 from waymondo/with-region-or-line, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux dc1606b 034/112: Add crux-transpose-windows for swapping the buffers between two windows, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 2be95ea 040/112: Use read-from-minibuffer for the new file name, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e2124c8 023/112: Merge pull request #6 from verdammelt/patch-1, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 3c14b4a 024/112: Merge pull request #13 from jiegec/master, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 79e500e 030/112: Add multiple choice with completion for shell init files., ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux e6c7421 035/112: Remove crux-swap-windows and alias it to crux-transpose-windows, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 5938c84 036/112: Merge pull request #21 from dgtized/transpose-windows, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 6d11d2e 039/112: When opening a line above, don't reindent the current line,
ELPA Syncer <=
- [nongnu] elpa/crux 1967a75 041/112: Allow users to create directories with crux-rename-file-and-buffer, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 582a68d 046/112: Fix the version header, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux bcbfdec 048/112: Don't assume ido when offering files from recentf (#33), ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 3b377b4 054/112: Add smart kill line function, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 1c2c179 061/112: Improve a docstring, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 2b6ddf0 060/112: Add missing space, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 5a7201a 062/112: Fix a docstring, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux 32baf6a 064/112: Bump the development version, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux a71669e 033/112: Merge pull request #17 from jiegec/master, ELPA Syncer, 2021/08/11
- [nongnu] elpa/crux cf547b7 037/112: Typo Fix: Missed an s in transpose, ELPA Syncer, 2021/08/11