Introduce compatibility code for looking-back

This commit is contained in:
Carsten Dominik 2009-11-23 12:44:49 +01:00
parent d60d003980
commit db5c9d73ec
5 changed files with 49 additions and 5 deletions

View File

@ -1,5 +1,15 @@
2009-11-23 Carsten Dominik <carsten.dominik@gmail.com> 2009-11-23 Carsten Dominik <carsten.dominik@gmail.com>
* org-mouse.el (org-mouse-end-headline, org-mouse-insert-item)
(org-mouse-context-menu): Use `org-looking-back'.
* org.el (org-cycle-level): Use `org-looking-back'.
* org-list.el (org-cycle-item-indentation): Use
`org-looking-back'.
* org-compat.el (org-looking-back): New function.
* org.el (org-insert-heading): Catch before-first-headline when * org.el (org-insert-heading): Catch before-first-headline when
inserting a headline. inserting a headline.

View File

@ -362,6 +362,40 @@ TIME defaults to the current time."
(time-to-seconds (or time (current-time))) (time-to-seconds (or time (current-time)))
(float-time time))) (float-time time)))
; XEmacs does not have `looking-back'.
(if (fboundp 'looking-back)
(defalias 'org-looking-back 'looking-back)
(defun org-looking-back (regexp &optional limit greedy)
"Return non-nil if text before point matches regular expression REGEXP.
Like `looking-at' except matches before point, and is slower.
LIMIT if non-nil speeds up the search by specifying a minimum
starting position, to avoid checking matches that would start
before LIMIT.
If GREEDY is non-nil, extend the match backwards as far as
possible, stopping when a single additional previous character
cannot be part of a match for REGEXP. When the match is
extended, its starting position is allowed to occur before
LIMIT."
(let ((start (point))
(pos
(save-excursion
(and (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t)
(point)))))
(if (and greedy pos)
(save-restriction
(narrow-to-region (point-min) start)
(while (and (> pos (point-min))
(save-excursion
(goto-char pos)
(backward-char 1)
(looking-at (concat "\\(?:" regexp "\\)\\'"))))
(setq pos (1- pos)))
(save-excursion
(goto-char pos)
(looking-at (concat "\\(?:" regexp "\\)\\'")))))
(not (null pos)))))
(provide 'org-compat) (provide 'org-compat)
;; arch-tag: a0a0579f-e68c-4bdf-9e55-93768b846bbe ;; arch-tag: a0a0579f-e68c-4bdf-9e55-93768b846bbe

View File

@ -1049,7 +1049,7 @@ Assumes cursor in item line."
(org-adapt-indentation nil)) (org-adapt-indentation nil))
(cond (cond
((and (looking-at "[ \t]*$") ((and (looking-at "[ \t]*$")
(looking-back "^\\([ \t]*\\)\\([-+*]\\|[0-9]+[).]\\)[ \t]+")) (org-looking-back "^\\([ \t]*\\)\\([-+*]\\|[0-9]+[).]\\)[ \t]+"))
(setq this-command 'org-cycle-item-indentation) (setq this-command 'org-cycle-item-indentation)
(if (eq last-command 'org-cycle-item-indentation) (if (eq last-command 'org-cycle-item-indentation)
(condition-case nil (condition-case nil

View File

@ -189,7 +189,7 @@ Changing this variable requires a restart of Emacs to get activated."
(interactive) (interactive)
(end-of-line) (end-of-line)
(skip-chars-backward "\t ") (skip-chars-backward "\t ")
(when (looking-back ":[A-Za-z]+:") (when (org-looking-back ":[A-Za-z]+:")
(skip-chars-backward ":A-Za-z") (skip-chars-backward ":A-Za-z")
(skip-chars-backward "\t "))) (skip-chars-backward "\t ")))
@ -607,7 +607,7 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
(:end ; insert text here (:end ; insert text here
(skip-chars-backward " \t") (skip-chars-backward " \t")
(kill-region (point) (point-at-eol)) (kill-region (point) (point-at-eol))
(unless (looking-back org-mouse-punctuation) (unless (org-looking-back org-mouse-punctuation)
(insert (concat org-mouse-punctuation " "))))) (insert (concat org-mouse-punctuation " ")))))
(insert text) (insert text)
@ -674,7 +674,7 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
'org-mode-restart)))) 'org-mode-restart))))
((or (eolp) ((or (eolp)
(and (looking-at "\\( \\|\t\\)\\(+:[0-9a-zA-Z_:]+\\)?\\( \\|\t\\)+$") (and (looking-at "\\( \\|\t\\)\\(+:[0-9a-zA-Z_:]+\\)?\\( \\|\t\\)+$")
(looking-back " \\|\t"))) (org-looking-back " \\|\t")))
(org-mouse-popup-global-menu)) (org-mouse-popup-global-menu))
((get-context :checkbox) ((get-context :checkbox)
(popup-menu (popup-menu

View File

@ -6285,7 +6285,7 @@ in the region."
(defun org-cycle-level () (defun org-cycle-level ()
(let ((org-adapt-indentation nil)) (let ((org-adapt-indentation nil))
(when (and (looking-at "[ \t]*$") (when (and (looking-at "[ \t]*$")
(looking-back (org-looking-back
(concat "^\\(\\*+\\)[ \t]+\\(" org-todo-regexp "\\)?[ \t]*"))) (concat "^\\(\\*+\\)[ \t]+\\(" org-todo-regexp "\\)?[ \t]*")))
(setq this-command 'org-cycle-level) (setq this-command 'org-cycle-level)
(if (eq last-command 'org-cycle-level) (if (eq last-command 'org-cycle-level)