On 07/21/2011 08:38 PM, Eric M. Ludlam wrote:
> [...] snip
>>>> On 07/05/2011 12:19 AM, Liu Binsheng wrote:
>>>>> When I use semantic-complete-jump-local to jump in a buffer, and then
>>>>> switch to another buffer, the cursor in the new buffer automatically
>>>>> locate in some tag I previously jumped to.
>>>>> For example, I use semantic-complete-jump-local to jump to function a
>>>>> in file a.el, and move the cursor to another line in the same file.
>>>>> Then I switch to file b.el and use semantic-complete-jump-local to
>>>>> jump to function b in file b.el.
>>>>> Now if I switch back to file a.el, the cursor automatically locate in
>>>>> function a instead of the correct line.
>>>>> This behavior makes me sometimes confused because I have to relocate
>>>>> the cursor. Is it intended or configurable?
> Hi Again,
> Richard Kim posted about a different problem also related to push-mark.
> That made me re-examine what was going on in there, when I discovered
> that the act of getting the mode of a tag, causes the point to move in
> those non-current buffers.
> As such, the below patch for modern Emacsen fixed the bouncing cursor
> problem. I don't know when save-current-buffer was introduced to know
> if it should be permanent.
> For Richard's problem (Possible bug in semantic-tag-buffer), I see a
> bigger bugaboo which was that the mode fetching was written when I was
> attempting to get multi-mode semantic working, so it is moving to a tag
> location, and asking what the mode is RiGHT THERE, which is a waste of
> time in current CEDET which doesn't support multi-mode.
> It will probably be better to just remove all that extra stuff, and get
> a hack matching against auto-mode-alist instead. That will fix Richards
> case, and this case at the same time.
> Of course, the whole point of checking the mode was to compress out
> duplicates, and not duplicates if those tags belonged to totally
> different languages. I don't recall why such strict tag duplicate
> removal was needed. Perhaps that whole feature can be eliminated?
> What to others who use the bookmark mode think of that?
To reply to myself, here is a revised version of the function discussed
(defun semantic-tag-mode (&optional tag)
"Return the major mode active for TAG.
TAG defaults to the tag at point in current buffer.
If TAG has a :mode property return it.
If point is inside TAG bounds, return the major mode active at point.
Return the major mode active at beginning of TAG otherwise.
See also the function `semantic-ctxt-current-mode'."
(or tag (setq tag (semantic-current-tag)))
(or (semantic--tag-get-property tag :mode)
(let ((buffer (semantic-tag-buffer tag))
(start (semantic-tag-start tag)))
(and buffer (buffer-live-p buffer) (set-buffer buffer))
What I found is that semantic-ctxt-current-mode takes a point, and if a
mode doesn't overload this function, it is a no-op. This version still
passes all my tests, but will also still work with Semantic grammars,
which is where the multiple modes comes in.
I also included Richard's check for live buffers.
Let me know if this works out for the misc use cases, and I'll check it in.