Browse Source

Let pcomplete handle drawers.

* org-pcomplete.el (pcomplete/org-mode/drawer): New function
to complete drawer at point.
(org-thing-at-point): Use it.

Thanks to Nick Dokos for a request in this area.
Bastien Guerry 13 years ago
parent
commit
1742683e4f
1 changed files with 26 additions and 1 deletions
  1. 26 1
      lisp/org-pcomplete.el

+ 26 - 1
lisp/org-pcomplete.el

@@ -84,8 +84,16 @@ The return value is a string naming the thing at point."
 	   (equal (char-after (point-at-bol)) ?*))
       (cons "tag" nil))
      ((and (equal (char-before beg1) ?:)
-	   (not (equal (char-after (point-at-bol)) ?*)))
+	   (not (equal (char-after (point-at-bol)) ?*))
+	   (save-excursion
+	     (move-beginning-of-line 1)
+	     (skip-chars-backward "[ \t\n]")
+	     (or (looking-back org-drawer-regexp)
+		 (looking-back org-property-re))))
       (cons "prop" nil))
+     ((and (equal (char-before beg1) ?:)
+	   (not (equal (char-after (point-at-bol)) ?*)))
+      (cons "drawer" nil))
      (t nil))))
 
 (defun org-command-at-point ()
@@ -239,6 +247,23 @@ This needs more work, to handle headings with lots of spaces in them."
 	     lst))
    (substring pcomplete-stub 1)))
 
+(defun pcomplete/org-mode/drawer ()
+  "Complete a drawer name."
+  (let ((spc (save-excursion
+	       (move-beginning-of-line 1)
+	       (looking-at "^\\([ \t]*\\):")
+	       (match-string 1)))
+	(cpllist (mapcar (lambda (x) (concat x ": ")) org-drawers)))
+    (pcomplete-here cpllist
+     (substring pcomplete-stub 1)
+     (unless (or (not (delete
+		       nil
+		       (mapcar (lambda(x)
+				 (string-match (substring pcomplete-stub 1) x))
+			       cpllist)))
+		 (looking-at "[ \t]*\n.*:END:"))
+       (save-excursion (insert "\n" spc ":END:"))))))
+
 (defun pcomplete/org-mode/block-option/src ()
   "Complete the arguments of a begin_src block.
 Complete a language in the first field, the header arguments and switches."