summaryrefslogtreecommitdiff
path: root/lisp/org/org-macs.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/org/org-macs.el')
-rw-r--r--lisp/org/org-macs.el89
1 files changed, 82 insertions, 7 deletions
diff --git a/lisp/org/org-macs.el b/lisp/org/org-macs.el
index 2a7ab66a339..f25efe07f33 100644
--- a/lisp/org/org-macs.el
+++ b/lisp/org/org-macs.el
@@ -34,6 +34,7 @@
(require 'cl-lib)
(require 'format-spec)
+(declare-function org-show-context "org" (&optional key))
(declare-function org-string-collate-lessp "org-compat" (s1 s2 &optional locale ignore-case))
(defvar org-ts-regexp0)
@@ -122,7 +123,7 @@ means that the buffer should stay alive during the operation,
because otherwise all these markers will point to nowhere."
(declare (debug (form body)) (indent 1))
(org-with-gensyms (data invisible-types markers?)
- `(let* ((,invisible-types '(org-hide-block org-hide-drawer outline))
+ `(let* ((,invisible-types '(org-hide-block outline))
(,markers? ,use-markers)
(,data
(mapcar (lambda (o)
@@ -416,6 +417,7 @@ is selected, only the bare key is returned."
(let ((inhibit-quit t)
(buffer (org-switch-to-buffer-other-window "*Org Select*"))
(prompt (or prompt "Select: "))
+ case-fold-search
current)
(unwind-protect
(catch 'exit
@@ -644,6 +646,25 @@ The number of levels is controlled by `org-inlinetask-min-level'."
limit-level)))
(format "\\*\\{1,%d\\} " nstars)))))
+(defun org--line-empty-p (n)
+ "Is the Nth next line empty?
+Counts the current line as N = 1 and the previous line as N = 0;
+see `beginning-of-line'."
+ (and (not (bobp))
+ (save-excursion
+ (beginning-of-line n)
+ (looking-at-p "[ \t]*$"))))
+
+(defun org-previous-line-empty-p ()
+ "Is the previous line a blank line?
+When NEXT is non-nil, check the next line instead."
+ (org--line-empty-p 0))
+
+(defun org-next-line-empty-p ()
+ "Is the previous line a blank line?
+When NEXT is non-nil, check the next line instead."
+ (org--line-empty-p 2))
+
;;; Motion
@@ -695,7 +716,9 @@ SPEC is the invisibility spec, as a symbol."
(let ((o (make-overlay from to nil 'front-advance)))
(overlay-put o 'evaporate t)
(overlay-put o 'invisible spec)
- (overlay-put o 'isearch-open-invisible #'delete-overlay))))
+ (overlay-put o
+ 'isearch-open-invisible
+ (lambda (&rest _) (org-show-context 'isearch))))))
@@ -920,7 +943,8 @@ if necessary."
(if (<= (length s) maxlength)
s
(let* ((n (max (- maxlength 4) 1))
- (re (concat "\\`\\(.\\{1," (int-to-string n) "\\}[^ ]\\)\\([ ]\\|\\'\\)")))
+ (re (concat "\\`\\(.\\{1," (number-to-string n)
+ "\\}[^ ]\\)\\([ ]\\|\\'\\)")))
(if (string-match re s)
(concat (match-string 1 s) "...")
(concat (substring s 0 (max (- maxlength 3) 0)) "...")))))
@@ -1065,10 +1089,16 @@ the value in cdr."
(get-text-property (or (next-single-property-change 0 prop s) 0)
prop s)))
-(defun org-invisible-p (&optional pos)
+(defun org-invisible-p (&optional pos folding-only)
"Non-nil if the character after POS is invisible.
-If POS is nil, use `point' instead."
- (get-char-property (or pos (point)) 'invisible))
+If POS is nil, use `point' instead. When optional argument
+FOLDING-ONLY is non-nil, only consider invisible parts due to
+folding of a headline, a block or a drawer, i.e., not because of
+fontification."
+ (let ((value (get-char-property (or pos (point)) 'invisible)))
+ (cond ((not value) nil)
+ (folding-only (memq value '(org-hide-block outline)))
+ (t value))))
(defun org-truely-invisible-p ()
"Check if point is at a character currently not visible.
@@ -1086,6 +1116,18 @@ move it back by one char before doing this check."
(backward-char 1))
(org-invisible-p)))
+(defun org-find-visible ()
+ "Return closest visible buffer position, or `point-max'"
+ (if (org-invisible-p)
+ (next-single-char-property-change (point) 'invisible)
+ (point)))
+
+(defun org-find-invisible ()
+ "Return closest invisible buffer position, or `point-max'"
+ (if (org-invisible-p)
+ (point)
+ (next-single-char-property-change (point) 'invisible)))
+
;;; Time
@@ -1182,8 +1224,41 @@ Return 0. if S is not recognized as a valid value."
((string-match org-ts-regexp0 s) (org-2ft s))
(t 0.)))))
-
+(defun org-scroll (key &optional additional-keys)
+ "Receive KEY and scroll the current window accordingly.
+When ADDITIONAL-KEYS is not nil, also include SPC and DEL in the
+allowed keys for scrolling, as expected in the export dispatch
+window."
+ (let ((scrlup (if additional-keys '(?\s 22) 22))
+ (scrldn (if additional-keys `(?\d 134217846) 134217846)))
+ (eval
+ `(cl-case ,key
+ ;; C-n
+ (14 (if (not (pos-visible-in-window-p (point-max)))
+ (ignore-errors (scroll-up 1))
+ (message "End of buffer")
+ (sit-for 1)))
+ ;; C-p
+ (16 (if (not (pos-visible-in-window-p (point-min)))
+ (ignore-errors (scroll-down 1))
+ (message "Beginning of buffer")
+ (sit-for 1)))
+ ;; SPC or
+ (,scrlup
+ (if (not (pos-visible-in-window-p (point-max)))
+ (scroll-up nil)
+ (message "End of buffer")
+ (sit-for 1)))
+ ;; DEL
+ (,scrldn (if (not (pos-visible-in-window-p (point-min)))
+ (scroll-down nil)
+ (message "Beginning of buffer")
+ (sit-for 1)))))))
(provide 'org-macs)
+;; Local variables:
+;; generated-autoload-file: "org-loaddefs.el"
+;; End:
+
;;; org-macs.el ends here