|
@@ -15457,6 +15457,30 @@ leave it alone. If it is larger than ind, set it to the target."
|
|
|
(concat (make-string i1 ?\ ) l)
|
|
|
l)))
|
|
|
|
|
|
+(defun org-remove-indentation (code &optional n)
|
|
|
+ "Remove the maximum common indentation from the lines in CODE.
|
|
|
+N may optionally be the number of spaces to remove."
|
|
|
+ (with-temp-buffer
|
|
|
+ (insert code)
|
|
|
+ (org-do-remove-indentation n)
|
|
|
+ (buffer-string)))
|
|
|
+
|
|
|
+(defun org-do-remove-indentation (&optional n)
|
|
|
+ "Remove the maximum common indentation from the buffer."
|
|
|
+ (let ((min 10000) re)
|
|
|
+ (if n
|
|
|
+ (setq min n)
|
|
|
+ (goto-char (point-min))
|
|
|
+ (while (re-search-forward "^ +[^ \n]" nil t)
|
|
|
+ (setq min (min min (1- (- (match-end 0) (match-beginning 0)))))))
|
|
|
+ (unless (= min 0)
|
|
|
+ (setq re (format "^ \\{%d\\}" min))
|
|
|
+ (goto-char (point-min))
|
|
|
+ (while (re-search-forward re nil t)
|
|
|
+ (replace-match "")
|
|
|
+ (end-of-line 1))
|
|
|
+ n)))
|
|
|
+
|
|
|
(defun org-base-buffer (buffer)
|
|
|
"Return the base buffer of BUFFER, if it has one. Else return the buffer."
|
|
|
(if (not buffer)
|