Move some indentation functions in "org-macs.el", remove others

* lisp/org-macs.el (org-get-indentation): Moved from "org.el"
(org-get-string-indentation):
(org-fix-indentation): Remove functions.
This commit is contained in:
Nicolas Goaziou 2018-01-20 15:52:11 +01:00
parent 73861065fc
commit b7e94882ea
3 changed files with 46 additions and 62 deletions

View File

@ -212,6 +212,10 @@ See docstring for details.
See docstring for details.
** Removed functions
*** ~org-get-string-indentation~
It was not used throughout the code base.
*** ~org-fix-indentation~
It was not used throughout code base.
*** ~org-try-structure-completion~
Org Tempo may be used as a replacement. See details above.
** Removed variables

View File

@ -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

View File

@ -21123,41 +21123,6 @@ If there is no description, use the link target."
(interactive "p")
(self-insert-command N))
(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-get-string-indentation (s)
"What indentation has S due to SPACE and TAB at the beginning of the string?"
(let ((n -1) (i 0) (w tab-width) c)
(catch 'exit
(while (< (setq n (1+ n)) (length s))
(setq c (aref s n))
(cond ((= c ?\ ) (setq i (1+ i)))
((= c ?\t) (setq i (* (/ (+ w i) w) w)))
(t (throw 'exit t)))))
i))
(defun org-fix-indentation (line ind)
"Fix indentation in LINE.
IND is a cons cell with target and minimum indentation.
If the current indentation in LINE is smaller than the minimum,
leave it alone. If it is larger than ind, set it to the target."
(let* ((l (org-remove-tabs line))
(i (org-get-indentation l))
(i1 (car ind)) (i2 (cdr ind)))
(when (>= i i2) (setq l (substring line i2)))
(if (> i1 0)
(concat (make-string i1 ?\ ) l)
l)))
(defun org-fill-template (template alist)
"Find each %key of ALIST in TEMPLATE and replace it."
(let ((case-fold-search nil))