[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
complete-tag at the end of a buffer
From: |
Sarah Weissman |
Subject: |
complete-tag at the end of a buffer |
Date: |
Fri, 8 Feb 2013 21:51:21 -0500 |
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))))))
- complete-tag at the end of a buffer,
Sarah Weissman <=