|
@@ -266,6 +266,48 @@ If DELETE is non-nil, delete all those overlays."
|
|
|
(t (push ov found))))))
|
|
|
|
|
|
|
|
|
+
|
|
|
+;;; Indentation
|
|
|
+
|
|
|
+(defun org-get-indentation (&optional line)
|
|
|
+ "Get the indentation of the current line, interpreting tabs.
|
|
|
+When LINE is given, assume it represents a line and compute its indentation."
|
|
|
+ (if line
|
|
|
+ (when (string-match "^ *" (org-remove-tabs line))
|
|
|
+ (match-end 0))
|
|
|
+ (save-excursion
|
|
|
+ (beginning-of-line 1)
|
|
|
+ (skip-chars-forward " \t")
|
|
|
+ (current-column))))
|
|
|
+
|
|
|
+(defun org-do-remove-indentation (&optional n)
|
|
|
+ "Remove the maximum common indentation from the buffer.
|
|
|
+When optional argument N is a positive integer, remove exactly
|
|
|
+that much characters from indentation, if possible. Return nil
|
|
|
+if it fails."
|
|
|
+ (catch :exit
|
|
|
+ (goto-char (point-min))
|
|
|
+ ;; Find maximum common indentation, if not specified.
|
|
|
+ (let ((n (or n
|
|
|
+ (let ((min-ind (point-max)))
|
|
|
+ (save-excursion
|
|
|
+ (while (re-search-forward "^[ \t]*\\S-" nil t)
|
|
|
+ (let ((ind (1- (current-column))))
|
|
|
+ (if (zerop ind) (throw :exit nil)
|
|
|
+ (setq min-ind (min min-ind ind))))))
|
|
|
+ min-ind))))
|
|
|
+ (if (zerop n) (throw :exit nil)
|
|
|
+ ;; Remove exactly N indentation, but give up if not possible.
|
|
|
+ (while (not (eobp))
|
|
|
+ (let ((ind (progn (skip-chars-forward " \t") (current-column))))
|
|
|
+ (cond ((eolp) (delete-region (line-beginning-position) (point)))
|
|
|
+ ((< ind n) (throw :exit nil))
|
|
|
+ (t (indent-line-to (- ind n))))
|
|
|
+ (forward-line)))
|
|
|
+ ;; Signal success.
|
|
|
+ t))))
|
|
|
+
|
|
|
+
|
|
|
|
|
|
;;; String manipulation
|
|
|
|
|
@@ -460,33 +502,6 @@ as-is if removal failed."
|
|
|
(insert code)
|
|
|
(if (org-do-remove-indentation n) (buffer-string) code)))
|
|
|
|
|
|
-(defun org-do-remove-indentation (&optional n)
|
|
|
- "Remove the maximum common indentation from the buffer.
|
|
|
-When optional argument N is a positive integer, remove exactly
|
|
|
-that much characters from indentation, if possible. Return nil
|
|
|
-if it fails."
|
|
|
- (catch :exit
|
|
|
- (goto-char (point-min))
|
|
|
- ;; Find maximum common indentation, if not specified.
|
|
|
- (let ((n (or n
|
|
|
- (let ((min-ind (point-max)))
|
|
|
- (save-excursion
|
|
|
- (while (re-search-forward "^[ \t]*\\S-" nil t)
|
|
|
- (let ((ind (1- (current-column))))
|
|
|
- (if (zerop ind) (throw :exit nil)
|
|
|
- (setq min-ind (min min-ind ind))))))
|
|
|
- min-ind))))
|
|
|
- (if (zerop n) (throw :exit nil)
|
|
|
- ;; Remove exactly N indentation, but give up if not possible.
|
|
|
- (while (not (eobp))
|
|
|
- (let ((ind (progn (skip-chars-forward " \t") (current-column))))
|
|
|
- (cond ((eolp) (delete-region (line-beginning-position) (point)))
|
|
|
- ((< ind n) (throw :exit nil))
|
|
|
- (t (indent-line-to (- ind n))))
|
|
|
- (forward-line)))
|
|
|
- ;; Signal success.
|
|
|
- t))))
|
|
|
-
|
|
|
|
|
|
|
|
|
;;; List manipulation
|