diff --git a/lisp/ChangeLog b/lisp/ChangeLog index edcea7461..ef268615d 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,15 @@ 2009-11-23 Carsten Dominik + * 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 inserting a headline. diff --git a/lisp/org-compat.el b/lisp/org-compat.el index 4fd2777ee..838c11cbf 100644 --- a/lisp/org-compat.el +++ b/lisp/org-compat.el @@ -362,6 +362,40 @@ TIME defaults to the current time." (time-to-seconds (or time (current-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) ;; arch-tag: a0a0579f-e68c-4bdf-9e55-93768b846bbe diff --git a/lisp/org-list.el b/lisp/org-list.el index c60e01563..7c4031f19 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -1049,7 +1049,7 @@ Assumes cursor in item line." (org-adapt-indentation nil)) (cond ((and (looking-at "[ \t]*$") - (looking-back "^\\([ \t]*\\)\\([-+*]\\|[0-9]+[).]\\)[ \t]+")) + (org-looking-back "^\\([ \t]*\\)\\([-+*]\\|[0-9]+[).]\\)[ \t]+")) (setq this-command 'org-cycle-item-indentation) (if (eq last-command 'org-cycle-item-indentation) (condition-case nil diff --git a/lisp/org-mouse.el b/lisp/org-mouse.el index 76ee91081..fcb788628 100644 --- a/lisp/org-mouse.el +++ b/lisp/org-mouse.el @@ -189,7 +189,7 @@ Changing this variable requires a restart of Emacs to get activated." (interactive) (end-of-line) (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 "\t "))) @@ -607,7 +607,7 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:" (:end ; insert text here (skip-chars-backward " \t") (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 text) @@ -674,7 +674,7 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:" 'org-mode-restart)))) ((or (eolp) (and (looking-at "\\( \\|\t\\)\\(+:[0-9a-zA-Z_:]+\\)?\\( \\|\t\\)+$") - (looking-back " \\|\t"))) + (org-looking-back " \\|\t"))) (org-mouse-popup-global-menu)) ((get-context :checkbox) (popup-menu diff --git a/lisp/org.el b/lisp/org.el index 831848f2f..89fb3ebb8 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -6285,7 +6285,7 @@ in the region." (defun org-cycle-level () (let ((org-adapt-indentation nil)) (when (and (looking-at "[ \t]*$") - (looking-back + (org-looking-back (concat "^\\(\\*+\\)[ \t]+\\(" org-todo-regexp "\\)?[ \t]*"))) (setq this-command 'org-cycle-level) (if (eq last-command 'org-cycle-level)