summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Dominik <carsten.dominik@gmail.com>2009-11-23 12:44:49 +0100
committerCarsten Dominik <carsten.dominik@gmail.com>2009-11-23 12:44:49 +0100
commitdb5c9d73ecfc5418ee44699aa6d5265ecc53044d (patch)
treee3b9ab416997eba6d9660eb3d8d7ef0ad3279638
parentd60d003980e8a595a5ddbb645f165d0e2c852fa1 (diff)
downloadorg-mode-db5c9d73ecfc5418ee44699aa6d5265ecc53044d.tar.gz
Introduce compatibility code for looking-back
-rwxr-xr-xlisp/ChangeLog10
-rw-r--r--lisp/org-compat.el34
-rw-r--r--lisp/org-list.el2
-rw-r--r--lisp/org-mouse.el6
-rw-r--r--lisp/org.el2
5 files changed, 49 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index edcea74..ef26861 100755
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,15 @@
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
inserting a headline.
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 4fd2777..838c11c 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 c60e015..7c4031f 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 76ee910..fcb7886 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 831848f..89fb3eb 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)