From: Sarah Weissman <seweissman@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: complete-tag at the end of a buffer
Date: Fri, 8 Feb 2013 21:51:21 -0500 [thread overview]
Message-ID: <CAK=EPVDjifSQPeVKigV5exE4xmkprFU=xWNx9d6APe47c5ufNw@mail.gmail.com> (raw)
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))))))
next reply other threads:[~2013-02-09 2:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-09 2:51 Sarah Weissman [this message]
2013-02-09 12:47 ` complete-tag at the end of a buffer Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAK=EPVDjifSQPeVKigV5exE4xmkprFU=xWNx9d6APe47c5ufNw@mail.gmail.com' \
--to=seweissman@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.