emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 93cd2cf 412/433: Add function for narrowed indentation


From: Dmitry Gutov
Subject: [elpa] master 93cd2cf 412/433: Add function for narrowed indentation
Date: Thu, 15 Mar 2018 19:44:46 -0400 (EDT)

branch: master
commit 93cd2cfc15a3cc5eae3b25cd92f08a9f6dc361a5
Author: Adam <address@hidden>
Commit: Adam <address@hidden>

    Add function for narrowed indentation
    
    Sometimes, modes rely on functions like (point-min) or overstep their region
    when attempting to indent a line. This can cause issues like
    https://github.com/AdamNiederer/vue-mode/issues/50
    
    This function narrows the buffer before indenting, preventing any issues 
which
    might arise from reliance on having one's own buffer.
    
    This doesn't change any defaults, but I figured some other mmm-mode 
derivatives
    could make use of this function.
---
 mmm-region.el | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/mmm-region.el b/mmm-region.el
index 6567b31..5b6bec1 100644
--- a/mmm-region.el
+++ b/mmm-region.el
@@ -871,6 +871,18 @@ This will be the value of `indent-line-function' for the 
whole
 buffer. It's supposed to delegate to the appropriate submode's
 indentation function. See `mmm-indent-line' as the starting point.")
 
+(defun mmm-indent-line-narrowed ()
+  "An indent function which works on modes which don't play well with mmm-mode.
+Calls `mmm-indent-line' internally, but narrows the buffer before indenting to
+appease modes which rely on constructs like (point-min) to indent."
+  (interactive)
+  (if mmm-current-overlay
+      (save-restriction
+        (narrow-to-region (overlay-start mmm-current-overlay)
+                          (overlay-end mmm-current-overlay))
+        (mmm-indent-line))
+    (mmm-indent-line)))
+
 (defun mmm-indent-line ()
   (interactive)
   (funcall



reply via email to

[Prev in Thread] Current Thread [Next in Thread]