summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-01-20 15:52:11 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-01-20 15:54:20 +0100
commitb7e94882eaf3106a904274b034896b33bfe0774f (patch)
tree74c62be85ad523aadadf6ee1291ed97d01a90c59
parent73861065fcf57809ce8efe2bee5653eef929dd7b (diff)
downloadorg-mode-b7e94882eaf3106a904274b034896b33bfe0774f.tar.gz
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.
-rw-r--r--etc/ORG-NEWS4
-rw-r--r--lisp/org-macs.el69
-rw-r--r--lisp/org.el35
3 files changed, 46 insertions, 62 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 65580d1..aedede2 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -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
diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 7cb13da..918c3a9 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -267,6 +267,48 @@ If DELETE is non-nil, delete all those overlays."
+;;; 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
(defsubst org-trim (s &optional keep-lead)
@@ -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
diff --git a/lisp/org.el b/lisp/org.el
index 545aebf..7044a05 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -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))