From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#9643: 24.0.90; pcomplete/tar and complete-within Date: Sat, 01 Oct 2011 21:01:43 -0400 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1317518309 24619 80.91.229.12 (2 Oct 2011 01:18:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 2 Oct 2011 01:18:29 +0000 (UTC) Cc: Per =?UTF-8?Q?Starb=C3=A4ck?= , 9643-done@debbugs.gnu.org To: Glenn Morris Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 02 03:18:24 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RAAhE-0006Je-59 for geb-bug-gnu-emacs@m.gmane.org; Sun, 02 Oct 2011 03:18:24 +0200 Original-Received: from localhost ([::1]:60673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAASE-0006uu-S0 for geb-bug-gnu-emacs@m.gmane.org; Sat, 01 Oct 2011 21:02:54 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:39048) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAASB-0006po-4g for bug-gnu-emacs@gnu.org; Sat, 01 Oct 2011 21:02:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RAAS9-0001t0-Bv for bug-gnu-emacs@gnu.org; Sat, 01 Oct 2011 21:02:50 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56009) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAAS9-0001sv-AM for bug-gnu-emacs@gnu.org; Sat, 01 Oct 2011 21:02:49 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1RAATL-00071Y-NH for bug-gnu-emacs@gnu.org; Sat, 01 Oct 2011 21:04:03 -0400 Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Sun, 02 Oct 2011 01:04:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 9643 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 9643@debbugs.gnu.org, monnier@iro.umontreal.ca Original-Received: via spool by 9643-done@debbugs.gnu.org id=D9643.131751738326912 (code D ref 9643); Sun, 02 Oct 2011 01:04:03 +0000 Original-Received: (at 9643-done) by debbugs.gnu.org; 2 Oct 2011 01:03:03 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RAASM-000701-SO for submit@debbugs.gnu.org; Sat, 01 Oct 2011 21:03:03 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.183] helo=ironport2-out.pppoe.ca) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RAASK-0006za-1o for 9643-done@debbugs.gnu.org; Sat, 01 Oct 2011 21:03:01 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAIO2h05FpZLc/2dsb2JhbAA4Cag1gQaBUwEBBVYjEAsOJhIUGA0kE758g3mDKwSgeYRD X-IronPort-AV: E=Sophos;i="4.68,475,1312171200"; d="scan'208";a="139568313" Original-Received: from 69-165-146-220.dsl.teksavvy.com (HELO pastel.home) ([69.165.146.220]) by ironport2-out.pppoe.ca with ESMTP/TLS/ADH-AES256-SHA; 01 Oct 2011 21:01:44 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id AC67B59291; Sat, 1 Oct 2011 21:01:43 -0400 (EDT) In-Reply-To: (Glenn Morris's message of "Fri, 30 Sep 2011 22:39:44 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.90 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Sat, 01 Oct 2011 21:04:03 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:52059 Archived-At: >> * In both my examples I'm trying to complete the tar filename, and it >> looked inside it to prepare for doing completion of arguments after >> this. If it only opened the tar file if I actually tried to complete >> more arguments *after* the tar filename it would be a lot better. > I agree. I've installed the patch below, which should fix this problem. Stefan === modified file 'lisp/ChangeLog' --- lisp/ChangeLog 2011-10-02 00:25:27 +0000 +++ lisp/ChangeLog 2011-10-02 00:59:53 +0000 @@ -1,3 +1,11 @@ +2011-10-02 Stefan Monnier + + * pcmpl-gnu.el (pcmpl-gnu-with-file-buffer): New macro (bug#9643). + (pcmpl-gnu-tar-buffer): Remove. + (pcmpl-gnu-with-file-buffer): Use it to avoid leaving the tar's buffer + avoid. Make sure pcomplete-suffix-list is only changed temporarily. + Don't look inside the tar's file is it's too large. + 2011-10-01 Chong Yidong * cus-edit.el (custom-mode-map): === modified file 'lisp/pcmpl-gnu.el' --- lisp/pcmpl-gnu.el 2011-10-01 02:38:46 +0000 +++ lisp/pcmpl-gnu.el 2011-10-02 00:56:47 +0000 @@ -128,22 +128,36 @@ :type 'regexp :group 'pcmpl-gnu) -(defvar pcmpl-gnu-tar-buffer nil) - ;; Only used in tar-mode buffers. (defvar tar-parse-info) (declare-function tar-header-name "tar-mode" t t) +(defmacro pcmpl-gnu-with-file-buffer (file &rest body) + "Run BODY inside a buffer visiting FILE." + (declare (debug t) (indent 1)) + (let ((exist (make-symbol "exist")) + (filesym (make-symbol "file")) + (buf (make-symbol "buf"))) + `(let* ((,filesym ,file) + (,exist (find-buffer-visiting ,filesym)) + (,buf (or ,exist (find-file-noselect ,filesym)))) + (unwind-protect + (with-current-buffer ,buf + ,@body) + (when (and (not ,exist) (buffer-live-p ,buf)) + (kill-buffer ,buf)))))) + ;;;###autoload (defun pcomplete/tar () "Completion for the GNU tar utility." ;; options that end in an equal sign will want further completion... (let (saw-option complete-within) - (setq pcomplete-suffix-list (cons ?= pcomplete-suffix-list)) + (let ((pcomplete-suffix-list (cons ?= pcomplete-suffix-list))) (while (pcomplete-match "^-" 0) (setq saw-option t) (if (pcomplete-match "^--" 0) (if (pcomplete-match "^--\\([^= \t\n\f]*\\)\\'" 0) + ;; FIXME: Extract this list from "tar --help". (pcomplete-here* '("--absolute-names" "--after-date=" @@ -281,8 +295,7 @@ (pcomplete-match-string 1 0))) ((pcomplete-match "\\`--volno-file=\\(.*\\)" 0) (pcomplete-here* (pcomplete-entries) - (pcomplete-match-string 1 0))))) - (setq pcomplete-suffix-list (cdr pcomplete-suffix-list)) + (pcomplete-match-string 1 0)))))) (unless saw-option (pcomplete-here (mapcar 'char-to-string @@ -291,15 +304,16 @@ (if (pcomplete-match "[xt]" 'first 1) (setq complete-within t))) (pcomplete-here (pcomplete-dirs-or-entries pcmpl-gnu-tarfile-regexp)) - (setq pcmpl-gnu-tar-buffer (find-file-noselect (pcomplete-arg 1))) (while (pcomplete-here - (if complete-within - (with-current-buffer pcmpl-gnu-tar-buffer - (mapcar - (function - (lambda (entry) - (tar-header-name entry))) - tar-parse-info)) + (if (and complete-within + (let* ((fa (file-attributes (pcomplete-arg 1))) + (size (nth 7 fa))) + (and (numberp size) + (< size large-file-warning-threshold)))) + (completion-table-dynamic + (lambda (string) + (pcmpl-gnu-with-file-buffer (pcomplete-arg 1) + (mapcar #'tar-header-name tar-parse-info)))) (pcomplete-entries)) nil 'identity))))