Skip to content

Instantly share code, notes, and snippets.

@lululau
Created July 23, 2015 16:04
Show Gist options
  • Save lululau/5208d224dbbff58060c4 to your computer and use it in GitHub Desktop.
Save lululau/5208d224dbbff58060c4 to your computer and use it in GitHub Desktop.
Put the tag defined in the same file with current buffer most above when there are more than one tags found and one tags found in buffer-file-name.
(defun helm-gtags--exec-global-command (type input &optional detail)
(let ((args (helm-gtags--construct-command type input)))
(helm-gtags--find-tag-directory)
(helm-gtags--save-current-context)
(let ((buf-coding buffer-file-coding-system) (current-buffer-filename (buffer-file-name)))
(with-current-buffer (helm-candidate-buffer 'global)
(let ((default-directory (helm-gtags--base-directory))
(input (car (last args)))
(coding-system-for-read buf-coding)
(coding-system-for-write buf-coding))
(if (zerop (apply 'process-file "global" nil '(t nil) nil args))
(progn (let ((global-out (buffer-string)))
(erase-buffer)
(insert (s-join "\n" (cdr (--map (car it) (--sort (or (s-suffix? (cadr it) current-buffer-filename) (string< (car it) (car other))) (--map (list it (substring it 0 (string-match ":[0-9]+:" it))) (split-string global-out "\n")))))))))
(error (format "%s: not found" input)))
(when detail
(helm-gtags--show-detail)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment