* complete-tag at the end of a buffer
@ 2013-02-09 2:51 Sarah Weissman
2013-02-09 12:47 ` Dmitry Gutov
0 siblings, 1 reply; 2+ messages in thread
From: Sarah Weissman @ 2013-02-09 2:51 UTC (permalink / raw)
To: help-gnu-emacs
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))))))
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: complete-tag at the end of a buffer
2013-02-09 2:51 complete-tag at the end of a buffer Sarah Weissman
@ 2013-02-09 12:47 ` Dmitry Gutov
0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Gutov @ 2013-02-09 12:47 UTC (permalink / raw)
To: Sarah Weissman; +Cc: help-gnu-emacs
Sarah Weissman <seweissman@gmail.com> writes:
> 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.
I'm pretty sure it's a bug.
It should be able to complete anywhere in the buffer.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-02-09 12:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-09 2:51 complete-tag at the end of a buffer Sarah Weissman
2013-02-09 12:47 ` Dmitry Gutov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).