From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sarah Weissman Newsgroups: gmane.emacs.help Subject: complete-tag at the end of a buffer Date: Fri, 8 Feb 2013 21:51:21 -0500 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1360378338 2117 80.91.229.3 (9 Feb 2013 02:52:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 9 Feb 2013 02:52:18 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Feb 09 03:52:40 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1U40YQ-00037y-M9 for geh-help-gnu-emacs@m.gmane.org; Sat, 09 Feb 2013 03:52:38 +0100 Original-Received: from localhost ([::1]:45408 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U40Y7-000423-Qr for geh-help-gnu-emacs@m.gmane.org; Fri, 08 Feb 2013 21:52:19 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:48453) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U40XG-0003vp-85 for help-gnu-emacs@gnu.org; Fri, 08 Feb 2013 21:51:29 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U40XD-0001Ho-5O for help-gnu-emacs@gnu.org; Fri, 08 Feb 2013 21:51:26 -0500 Original-Received: from mail-oa0-f50.google.com ([209.85.219.50]:45046) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U40XD-0001He-0M for help-gnu-emacs@gnu.org; Fri, 08 Feb 2013 21:51:23 -0500 Original-Received: by mail-oa0-f50.google.com with SMTP id l20so4701969oag.37 for ; Fri, 08 Feb 2013 18:51:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=94d/R8rNeXWa/n4HgVK5W2t/p2/N1bGnh9k5IqG7StI=; b=cvSxc+uPMzvEw8G5gxkqr06DIbhkW+orcNXTV8y1HoQq0F6+lMTSv2BX4ISh05pTz2 yzrY2L428IWZxJrIjPO830MRfyVg99UYKeD4hce6WDeACbZtGepb/C4l+2Ji3RET2u2d HhdVIVVgX2J2MD5ioX98g2limKWJTIsinn3+mGSegqGtzRnKdpeNF9sifdOnZMiPfIie GHYFJVgo/Scl0wvZ4bIHLMhN8slKX0r0u96QbIiYQ/8KNtizV8vyaTX6ScxVqQZGPn/t 34sBR/r23WNPdTxm5B4XUIb3dq5D4aUG4S/12X3alusxOpG3Tbktyf8ham3tw+Na7Gr+ Xz3Q== X-Received: by 10.60.30.42 with SMTP id p10mr5776588oeh.59.1360378281944; Fri, 08 Feb 2013 18:51:21 -0800 (PST) Original-Received: by 10.76.126.167 with HTTP; Fri, 8 Feb 2013 18:51:21 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.219.50 X-Mailman-Approved-At: Fri, 08 Feb 2013 21:52:15 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:89019 Archived-At: I thought I could implement general tab completion using tags in a custom mode by following the advice found here: http://emacsblog.org/2007/03/12/tab-completion-everywhere/ and simply replacing the call to dabbrev-expand with a call to complete-tag. This worked fine, except when trying to do completion at the end of the buffer, which generates an end-of-buffer error. This seems to be because tags-completion-at-point-function (called by complete-tags) is using forward-char without checking that it might go past the end. To get around this I wrote my own version of tags-completion-at-point-function, just to add in the extra check around each call to forward char, and my own version of complete-tag to call this function, but this seems kind of silly. Am I using the wrong entry point for completing tags in a normal buffer? Or is this a bug? Below I've included the original version and my version for tags-completion-at-point-function, for reference. (defun tags-completion-at-point-function () "Using tags, return a completion table for the text around point. If no tags table is loaded, do nothing and return nil." (when (or tags-table-list tags-file-name) (let ((completion-ignore-case (if (memq tags-case-fold-search '(t nil)) tags-case-fold-search case-fold-search)) (pattern (funcall (or find-tag-default-function (get major-mode 'find-tag-default-function) 'find-tag-default))) beg) (when pattern (save-excursion (forward-char (1- (length pattern))) (search-backward pattern) (setq beg (point)) (forward-char (length pattern)) (list beg (point) (tags-lazy-completion-table) :exclusive 'no)))))) (defun my-tags-completion-at-point-function () "Using tags, return a completion table for the text around point. If no tags table is loaded, do nothing and return nil." (when (or tags-table-list tags-file-name) (let ((completion-ignore-case (if (memq tags-case-fold-search '(t nil)) tags-case-fold-search case-fold-search)) (pattern (funcall (or find-tag-default-function (get major-mode 'find-tag-default-function) 'find-tag-default))) beg) (when pattern (save-excursion (save-excursion (end-of-buffer) (setq e (point))) (if (> (+ (point) (1- (length pattern))) e) (end-of-buffer) (forward-char (1- (length pattern)))) (search-backward pattern) (setq beg (point)) (if (> (+ (point) (1- (length pattern))) e) (end-of-buffer) (forward-char (length pattern))) (list beg (point) (tags-lazy-completion-table) :exclusive 'no))))))