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

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

[ELPA-diffs] /srv/bzr/emacs/elpa r214: Add adaptive-wrap-extra-indent.


From: Stefan Monnier
Subject: [ELPA-diffs] /srv/bzr/emacs/elpa r214: Add adaptive-wrap-extra-indent.
Date: Mon, 21 May 2012 00:46:36 -0400
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 214
author: Jonathan Kotta <address@hidden>  (tiny change)
committer: Stefan Monnier <address@hidden>
branch nick: elpa
timestamp: Mon 2012-05-21 00:46:36 -0400
message:
  Add adaptive-wrap-extra-indent.
  * adaptive-wrap/adaptive-wrap.el (adaptive-wrap-extra-indent): New var.
  (adaptive-wrap-fill-context-prefix): New function.
  (adaptive-wrap-prefix-function): Use it.
  (adaptive-wrap-prefix-mode): Add to visual-line custom group.
modified:
  packages/adaptive-wrap/adaptive-wrap.el
=== modified file 'packages/adaptive-wrap/adaptive-wrap.el'
--- a/packages/adaptive-wrap/adaptive-wrap.el   2012-01-05 11:25:27 +0000
+++ b/packages/adaptive-wrap/adaptive-wrap.el   2012-05-21 04:46:36 +0000
@@ -28,20 +28,69 @@
 
 ;;; Code:
 
+(defcustom adaptive-wrap-extra-indent 0
+  "Number of extra spaces to indent in `adaptive-wrap-prefix-mode'.
+
+`adaptive-wrap-prefix-mode' indents the visual lines to
+the level of the actual line plus `adaptive-wrap-extra-indent'.
+A negative value will do a relative de-indent.
+
+Examples:
+
+actual indent = 2
+extra indent = -1
+
+  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+ eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
+ enim ad minim veniam, quis nostrud exercitation ullamco laboris
+ nisi ut aliquip ex ea commodo consequat.
+
+actual indent = 2
+extra indent = 2
+
+  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
+    eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
+    enim ad minim veniam, quis nostrud exercitation ullamco laboris
+    nisi ut aliquip ex ea commodo consequat."
+  :type 'integer
+  :group 'visual-line)
+(make-local-variable 'adaptive-wrap-extra-indent)
+
+(defun adaptive-wrap-fill-context-prefix (beg en)
+  "Like `fill-context-prefix', but with length adjusted by 
`adaptive-wrap-extra-indent'."
+  (let* ((fcp (fill-context-prefix beg en))
+         (fcp-len (string-width fcp))
+         (fill-char (if (< 0 fcp-len)
+                        (string-to-char (substring fcp -1))
+                      ?\ )))
+    (cond
+     ((= 0 adaptive-wrap-extra-indent)
+      fcp)
+     ((< 0 adaptive-wrap-extra-indent)
+      (concat fcp
+              (make-string adaptive-wrap-extra-indent fill-char)))
+     ((< 0 (+ adaptive-wrap-extra-indent fcp-len))
+      (substring fcp
+                 0
+                 (+ adaptive-wrap-extra-indent fcp-len)))
+     (t
+      ""))))
+
 (defun adaptive-wrap-prefix-function (beg end)
   "Indent the region between BEG and END with adaptive filling."
   (goto-char beg)
   (while (< (point) end)
-    (let ((blp (line-beginning-position)))
+    (let ((lbp (line-beginning-position)))
       (put-text-property (point)
                          (progn (search-forward "\n" end 'move) (point))
                          'wrap-prefix
-                         (fill-context-prefix blp (point))))))
+                         (adaptive-wrap-fill-context-prefix lbp (point))))))
 
 ;;;###autoload
 (define-minor-mode adaptive-wrap-prefix-mode
   "Wrap the buffer text with adaptive filling."
   :lighter ""
+  :group 'visual-line
   (if adaptive-wrap-prefix-mode
       (jit-lock-register #'adaptive-wrap-prefix-function)
     (jit-lock-unregister #'adaptive-wrap-prefix-function)
@@ -50,6 +99,5 @@
         (widen)
         (remove-text-properties (point-min) (point-max) '(wrap-prefix nil))))))
 
-
 (provide 'adaptive-wrap)
 ;;; adaptive-wrap.el ends here


reply via email to

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