emacsorphanage / helm-gtags

GNU GLOBAL helm interface
204 stars 31 forks source link

This commit fixes a problem when calculating the position of beginning o... #106

Closed Mikiya closed 9 years ago

Mikiya commented 9 years ago

Hello again!

I have realized a problem in the previous patch!

Previously, it uses line-number-at-pos to get line number of defun. This works only when the cursor is on the same line as defun. However, I think we want to execute helm-gtags-parse-file at any place within a source code. It's more useful if preselect is available when the cursor is not on the same line as defun.

To achieve this, I tried to use helm-gtags--current-function-bound, but I faced another problem. The helm-gtags--current-function-bound uses beginning-of-defun to find the position of defun, however, return value of beginning-of-defun is not necessarily same as the value retrieved from global command. For example, line numbers will mismatch between beginning-of-defun and global. See the following example.

1: void 2: main() 3: { 4: puts("Hello world!"); 5: }

In this case, beginning-of-defun moves to line 1 while global returns line 2 on the other hand. Due to this mismatch, simple regex based comparison doesn't work in such case and results in inability to construct correct preselect. The simplest way to solve this problem is to use global to construct preselect regex pattern. In this patch, I introduced several functions to do it.

Kind regards!

Mikiya commented 9 years ago

BTW, this approach is not perfect, because a line number cannot be retrieved in the following cases:

To overcome this problem, "global -f" is required IMHO. It may results in running "global -f" command twice, but it could be a reasonable cost for convenience, if a user prefer to position based code browsing.