;;; emacs/hideshow/autoload.el -*- lexical-binding: t; -*- ;;;###autoload (defun +hideshow-haml-forward-sexp (arg) (haml-forward-sexp) (move-beginning-of-line 1)) ;;;###autoload (defun +hideshow-forward-block-by-indent (arg) (let ((start (current-indentation))) (forward-line) (unless (= start (current-indentation)) (let ((range (+hideshow-indent-range))) (goto-char (cadr range)) (end-of-line))))) ;; ;; Indentation detection ;; (defun +hideshow--empty-line-p () (string= "" (string-trim (thing-at-point 'line)))) (defun +hideshow--geq-or-empty-p () (or (+hideshow--empty-line-p) (>= (current-indentation) base))) (defun +hideshow--g-or-empty-p () (or (+hideshow--empty-line-p) (> (current-indentation) base))) (defun +hideshow--seek (start direction before skip predicate) "Seeks forward (if direction is 1) or backward (if direction is -1) from start, until predicate fails. If before is nil, it will return the first line where predicate fails, otherwise it returns the last line where predicate holds." (save-excursion (goto-char start) (goto-char (point-at-bol)) (let ((bnd (if (> 0 direction) (point-min) (point-max))) (pt (point))) (when skip (forward-line direction)) (cl-loop while (and (/= (point) bnd) (funcall predicate)) do (progn (when before (setq pt (point-at-bol))) (forward-line direction) (unless before (setq pt (point-at-bol))))) pt))) (defun +hideshow-indent-range (&optional point) "Return the point at the begin and end of the text block with the same (or greater) indentation. If `point' is supplied and non-nil it will return the begin and end of the block surrounding point." (save-excursion (when point (goto-char point)) (let ((base (current-indentation)) (begin (point)) (end (point))) (setq begin (+hideshow--seek begin -1 t nil #'+hideshow--geq-or-empty-p) begin (+hideshow--seek begin 1 nil nil #'+hideshow--g-or-empty-p) end (+hideshow--seek end 1 t nil #'+hideshow--geq-or-empty-p) end (+hideshow--seek end -1 nil nil #'+hideshow--empty-line-p)) (list begin end base))))