Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in helm-semantic #777

Closed
wants to merge 1 commit into from
Closed

Fix a bug in helm-semantic #777

wants to merge 1 commit into from

Conversation

tuhdo
Copy link
Contributor

@tuhdo tuhdo commented Dec 24, 2014

Currently, helm-semantic-source inserts tag candidates in its own
buffer. This causes a problem: semantic-format-tag-summarize adds
pointer information with characters like * and &, specific to C and C++
modes. However, since the function is called in helm buffer created
by (helm-candidate-buffer 'global), it is in fundamental-mode and cannot
insert tag string correctly. Pointer information with characters * and &
is stripped. To reproduce this bug:

  • Create an empty C or C++ file and insert only this line:

const char**** filename;

Then, run helm-semantic. The candidate is displayed as:

const char filename;

This change fixes this problem by setting the Helm buffer to the actual
major mode of the current code buffer. The function
helm-semantic-get-candidates because it calls
helm-semantic--fetch-candidates again, after being called once the
initform in helm-source-semantic.

Currently, helm-semantic-source inserts tag candidates in its own
buffer. This causes a problem: semantic-format-tag-summarize adds
pointer information with characters like * and &, specific to C and C++
modes. However, since the function is called in helm buffer created
by (helm-candidate-buffer 'global), it is in fundamental-mode and cannot
insert tag string correctly. Pointer information with characters * and &
is stripped. To reproduce this bug:

- Create an empty C or C++ file and insert only this line:

const char**** filename;

Then, run helm-semantic. The candidate is displayed as:

const char filename;

This change fixes this problem by setting the Helm buffer to the actual
major mode of the current code buffer. The function
helm-semantic-get-candidates because it calls
helm-semantic--fetch-candidates again, after being called once the
initform in helm-source-semantic.
@tuhdo
Copy link
Contributor Author

tuhdo commented Dec 24, 2014

You can read more about this issue on StackExchange.

@thierryvolpiatto
Copy link
Member

Tu Do notifications@github.com writes:

Currently, helm-semantic-source inserts tag candidates in its own
buffer. This causes a problem: semantic-format-tag-summarize adds
pointer information with characters like * and &, specific to C and C++
modes. However, since the function is called in helm buffer created
by (helm-candidate-buffer 'global), it is in fundamental-mode and cannot
insert tag string correctly. Pointer information with characters * and &
is stripped. To reproduce this bug:

  • Create an empty C or C++ file and insert only this line:

const char**** filename;

Then, run helm-semantic. The candidate is displayed as:

const char filename;

This change fixes this problem by setting the Helm buffer to the actual
major mode of the current code buffer. The function
helm-semantic-get-candidates because it calls
helm-semantic--fetch-candidates again, after being called once the
initform in helm-source-semantic.

Can you try this patch instead, looks simpler:

diff --git a/helm-semantic.el b/helm-semantic.el
index fc3b4e0..05b8880 100644
--- a/helm-semantic.el
+++ b/helm-semantic.el
@@ -98,12 +98,6 @@
(unless persistent
(pulse-momentary-highlight-one-line (point))))))

-(defun helm-semantic-get-candidates ()

  • "Get a list of candidates in the current buffer."
  • (split-string (with-temp-buffer
  •              (helm-semantic--fetch-candidates helm-semantic--tags-cache 0)
    

- (buffer-string)) "\n"))

(defun helm-semantic--maybe-set-needs-update ()
(with-helm-current-buffer
(let ((tick (buffer-modified-tick)))
@@ -113,13 +107,14 @@

(defvar helm-source-semantic nil)

-(defclass helm-semantic-source (helm-source-sync)
+(defclass helm-semantic-source (helm-source-in-buffer)
((init :initform (lambda ()
(helm-semantic--maybe-set-needs-update)
(setq helm-semantic--tags-cache (semantic-fetch-tags))
(with-current-buffer (helm-candidate-buffer 'global)

  •                   (helm-semantic--fetch-candidates helm-semantic--tags-cache 0))))
    
  • (candidates :initform 'helm-semantic-get-candidates)
  •                   (let ((major-mode (with-helm-current-buffer major-mode)))
    
  •                     (helm-semantic--fetch-candidates helm-semantic--tags-cache 0)))))
    
  • (get-line :initform 'buffer-substring)
    (persistent-help :initform "Show this entry")
    (keymap :initform 'helm-semantic-map)
    (mode-line :initform helm-semantic-mode-line)

Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997

@tuhdo
Copy link
Contributor Author

tuhdo commented Dec 24, 2014

It won't work because helm-semantic--fetch-candidates insert tag strings into a buffer, not returning a list. Maybe we can refactor it later. Applying your patch, executing it inserts strings into current code buffer.

@thierryvolpiatto
Copy link
Member

Tu Do notifications@github.com writes:

It won't work because helm-semantic--fetch-candidates insert tag
strings into a buffer, not returning a list. Maybe we can refactor it
later. Applying your patch, executing it inserts strings into current
code buffer.

You have to delete the old helm-semantic buffer, revert buffer, reload
helm-semantic.el and run again, or better to be sure install the file
and restart emacs.
It is working fine here.

Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997

thierryvolpiatto added a commit that referenced this pull request Dec 24, 2014
* helm-semantic.el (helm-semantic-source): Use helm-source-in-buffer.
(helm-semantic-get-candidates): Removed.
@tuhdo
Copy link
Contributor Author

tuhdo commented Dec 24, 2014

Your patch works fine now. I got an error because I had to apply it manually, since the patch is malformed when I copied it into my buffer. You can merge your fix.

@thierryvolpiatto
Copy link
Member

I have pushed to exp branch, just install it and try, you will see it
works fine.

Thanks.

Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997

@tuhdo
Copy link
Contributor Author

tuhdo commented Dec 24, 2014

Yes, it works fine.

@tuhdo tuhdo closed this Dec 24, 2014
@tuhdo
Copy link
Contributor Author

tuhdo commented Dec 24, 2014

I consider this is merged. Thanks.

@thierryvolpiatto
Copy link
Member

Tu Do notifications@github.com writes:

Your patch works fine now. I got an error because I had to apply it
manually, since the patch is malformed when I copied it into my
buffer.

Use shell-command-on-region' with "patch -p0 -d ...." from your mail buffer. For history fromshell-command-on-region' use as always `C-r'.

You can merge your fix.

Done, thanks.

Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants