emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r104395: * lisp/info-look.el: Convert


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r104395: * lisp/info-look.el: Convert to lexical-binding and completion-at-point.
Date: Fri, 27 May 2011 22:33:10 -0300
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 104395
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Fri 2011-05-27 22:33:10 -0300
message:
  * lisp/info-look.el: Convert to lexical-binding and completion-at-point.
  (info-lookup-completions-at-point): New function.
  (info-complete): Use it and completion-in-region.
modified:
  lisp/ChangeLog
  lisp/info-look.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-05-28 01:26:53 +0000
+++ b/lisp/ChangeLog    2011-05-28 01:33:10 +0000
@@ -1,3 +1,9 @@
+2011-05-28  Stefan Monnier  <address@hidden>
+
+       * info-look.el: Convert to lexical-binding and completion-at-point.
+       (info-lookup-completions-at-point): New function.
+       (info-complete): Use it and completion-in-region.
+
 2011-05-28  Drew Adams  <address@hidden>
 
        * isearch.el: Let M-e start with point at the first mismatched char.

=== modified file 'lisp/info-look.el'
--- a/lisp/info-look.el 2011-05-16 17:41:03 +0000
+++ b/lisp/info-look.el 2011-05-28 01:33:10 +0000
@@ -1,4 +1,4 @@
-;;; info-look.el --- major-mode-sensitive Info index lookup facility
+;;; info-look.el --- major-mode-sensitive Info index lookup facility -*- 
lexical-binding: t -*-
 ;; An older version of this was known as libc.el.
 
 ;; Copyright (C) 1995-1999, 2001-2011 Free Software Foundation, Inc.
@@ -357,7 +357,7 @@
        (setq node (nth 0 (car doc-spec))
              prefix (nth 2 (car doc-spec))
              suffix (nth 3 (car doc-spec)))
-       (when (condition-case error-data
+       (when (condition-case nil
                  (progn
                    ;; Don't need Index menu fontifications here, and
                    ;; they slow down the lookup.
@@ -473,7 +473,7 @@
                        (t (nth 1 (car doc-spec)))))
       (with-current-buffer buffer
        (message "Processing Info node `%s'..." node)
-       (when (condition-case error-data
+       (when (condition-case nil
                  (progn
                    (Info-goto-node node)
                    (setq doc-found t))
@@ -641,44 +641,41 @@
                         info-lookup-mode
                       (info-lookup-change-mode 'file)))))
 
+(defun info-lookup-completions-at-point (topic mode)
+  "Try to complete a help item."
+  (or mode (setq mode (info-lookup-select-mode)))
+  (when (info-lookup->mode-value topic mode)
+    (let ((modes (info-lookup-quick-all-modes topic mode))
+          (start (point))
+          try)
+      (while (and (not try) modes)
+        (setq mode (car modes)
+              modes (cdr modes)
+              try (info-lookup-guess-default* topic mode))
+        (goto-char start))
+      (when try
+        (let ((completions (info-lookup->completions topic mode)))
+          (when completions
+            (when (info-lookup->ignore-case topic mode)
+              (setq completions
+                    (lambda (string pred action)
+                      (let ((completion-ignore-case t))
+                        (complete-with-action
+                         action completions string pred)))))
+            (save-excursion
+              ;; Find the original symbol and zap it.
+              (end-of-line)
+              (while (and (search-backward try nil t)
+                          (< start (point))))
+              (list (match-beginning 0) (match-end 0) completions))))))))
+
 (defun info-complete (topic mode)
   "Try to complete a help item."
   (barf-if-buffer-read-only)
-  (or mode (setq mode (info-lookup-select-mode)))
-  (or (info-lookup->mode-value topic mode)
-      (error "No %s completion available for `%s'" topic mode))
-  (let ((modes (info-lookup-quick-all-modes topic mode))
-       (start (point))
-       try)
-    (while (and (not try) modes)
-      (setq mode (car modes)
-           modes (cdr modes)
-           try (info-lookup-guess-default* topic mode))
-      (goto-char start))
-    (and (not try)
-        (error "Found no %S to complete" topic))
-    (let ((completions (info-lookup->completions topic mode))
-         (completion-ignore-case (info-lookup->ignore-case topic mode))
-         completion)
-      (setq completion (try-completion try completions))
-      (cond ((not completion)
-            (ding)
-            (message "No match"))
-           ((stringp completion)
-            (or (assoc completion completions)
-                (setq completion (completing-read
-                                  (format "Complete %S: " topic)
-                                  completions nil t completion
-                                  info-lookup-history)))
-            ;; Find the original symbol and zap it.
-            (end-of-line)
-            (while (and (search-backward try nil t)
-                        (< start (point))))
-            (replace-match "")
-            (insert completion))
-           (t
-            (message "%s is complete"
-                     (capitalize (prin1-to-string topic))))))))
+  (let ((data (info-lookup-completions-at-point topic mode)))
+    (if (null data)
+        (error "No %s completion available for `%s' at point" topic mode)
+      (apply #'completion-in-region data))))
 
 
 ;;; Initialize some common modes.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]