Skip to content

Commit

Permalink
Revert "Optimize toggle run time"
Browse files Browse the repository at this point in the history
  • Loading branch information
zenozeng committed Mar 5, 2017
1 parent 44da0af commit dba8571
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions yafolding.el
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@
overlay))
(overlays-in beg end))))

(defun yafolding--current-indentation ()
"Determine indentation in (possibly invisible) current line."
(save-excursion
(back-to-indentation)
(current-column)))

(defun yafolding-should-ignore-current-line-p ()
"Return if should ignore current line."
(string-match-p "^[ \t]*$"
Expand All @@ -83,13 +77,13 @@
(forward-line 1)
(yafolding-get-indent-level))
(let ((indent-level 0)
(last-indentation (yafolding--current-indentation)))
(last-indentation (current-indentation)))
(save-excursion
(while (and (> (yafolding--current-indentation) 0)
(while (and (> (current-indentation) 0)
(> (line-number-at-pos) 1))
(forward-line -1)
(when (< (yafolding--current-indentation) last-indentation)
(setq last-indentation (yafolding--current-indentation))
(when (< (current-indentation) last-indentation)
(setq last-indentation (current-indentation))
(setq indent-level (+ 1 indent-level)))))
indent-level)))

Expand Down Expand Up @@ -121,10 +115,10 @@
If given, toggle all entries that start at INDENT-LEVEL."
(interactive)
(unless indent-level
(setq indent-level (yafolding-get-indent-level)))
(if (yafolding-get-overlays (point-min) (point-max))
(yafolding-show-all)
(unless indent-level
(setq indent-level (yafolding-get-indent-level)))
(yafolding-hide-all indent-level)))

(defun yafolding-ellipsis ()
Expand Down Expand Up @@ -156,21 +150,23 @@ If given, toggle all entries that start at INDENT-LEVEL."
"Show yafolding information of the current position."
(interactive)
(message "indentation: %d, indent level: %d, ingore current line: %s"
(yafolding--current-indentation)
(current-indentation)
(yafolding-get-indent-level)
(yafolding-should-ignore-current-line-p)))

(defun yafolding-get-element-region ()
"Get '(beg end) of current element."
(let ((beg (line-end-position))
(end (line-end-position))
(indentation (yafolding--current-indentation)))
(indentation (current-indentation)))
(save-excursion
(while (and (= (forward-line) 0)
(or (> (yafolding--current-indentation) indentation)
(next-line)
(while (and (< (line-number-at-pos) (line-number-at-pos (point-max)))
(or (> (current-indentation) indentation)
(yafolding-should-ignore-current-line-p)))
(unless (yafolding-should-ignore-current-line-p)
(setq end (line-end-position)))))
(setq end (line-end-position)))
(next-line))) ; using next-line instead of forward-line, for issue#23
(list beg end)))

(defun yafolding-hide-element ()
Expand Down Expand Up @@ -208,7 +204,7 @@ If given, toggle all entries that start at INDENT-LEVEL."
"Go back to parent element."
(interactive)
(re-search-backward (concat "^.\\{,"
(number-to-string (- (yafolding--current-indentation) 1))
(number-to-string (- (current-indentation) 1))
"\\}[^ \t]+")))

(defun yafolding-hide-parent-element ()
Expand Down

0 comments on commit dba8571

Please sign in to comment.