This file is indexed.

/usr/share/emacs/site-lisp/elpa-src/go-autocomplete-20170907/go-autocomplete.el is in elpa-go-autocomplete 20170907-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
;;; go-autocomplete.el --- auto-complete-mode backend for go-mode

;; Copyright (C) 2010

;; Author: Mikhail <tensai@cirno.in> Kuryshev
;; Keywords: languages

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Ensure that go-autocomplete in your load-path and add to your ~/.emacs
;; following line:
;;
;; (require 'go-autocomplete)

;; Also you could setup any combination (for example M-TAB)
;; for invoking auto-complete:
;;
;; (require 'auto-complete-config)
;; (define-key ac-mode-map (kbd "M-TAB") 'auto-complete)

;;; Code:

(eval-when-compile
  (require 'cl))

(require 'auto-complete)

(declare-function yas-expand-snippet "yasnippet")

(defgroup go-autocomplete nil
  "auto-complete for go language."
  :prefix "ac-go-"
  :group 'auto-complete)

(defcustom ac-go-expand-arguments-into-snippets t
  "Expand function arguments into snippets. This feature requires `yasnippet'."
  :type 'boolean
  :group 'go-autocomplete)

(defcustom ac-go-gocode-bin "gocode"
  "Overwrite path to gocode binary"
  :type 'string
  :group 'go-autocomplete)

;; Close gocode daemon at exit unless it was already running
(eval-after-load "go-mode"
  '(progn
     (let* ((user (or (getenv "USER") "all"))
            (sock (format (concat temporary-file-directory "gocode-daemon.%s") user)))
       (unless (file-exists-p sock)
         (add-hook 'kill-emacs-hook #'(lambda ()
                                        (ignore-errors
                                          (call-process "gocode" nil nil nil "close"))))))))

;(defvar go-reserved-keywords
;  '("break" "case" "chan" "const" "continue" "default" "defer" "else"
;    "fallthrough" "for" "func" "go" "goto" "if" "import" "interface"
;    "map" "package" "range" "return" "select" "struct" "switch" "type" "var")
;  "Go reserved keywords.")

(defun ac-comphist-sort (db collection prefix &optional threshold)
;; redefine to disable sorting
  (let (result
        (n 0)
        (total 0)
        (cur 0))
    (setq result (mapcar (lambda (a)
                           (when (and cur threshold)
                             (if (>= cur (* total threshold))
                                 (setq cur nil)
                               (incf n)
                               (incf cur (cdr a))))
                           (car a))
                         (mapcar (lambda (string)
				   (let ((score (ac-comphist-score db string prefix)))
				     (incf total score)
				     (cons string score)))
				 collection)))
    (if threshold
        (cons n result)
      result)))

(defun ac-go-invoke-autocomplete ()
  (let ((temp-buffer (generate-new-buffer "*gocode*")))
    (unwind-protect
        (progn
          (call-process-region (point-min)
                               (point-max)
                               ac-go-gocode-bin
                               nil
                               temp-buffer
                               nil
                               "-f=emacs"
                               "autocomplete"
                               (or (buffer-file-name) "")
                               (concat "c" (int-to-string (- (point) 1))))
          (with-current-buffer temp-buffer (buffer-string)))
      (kill-buffer temp-buffer))))

(defun ac-go-format-autocomplete (buffer-contents)
  (sort
   (split-string buffer-contents "\n" t)
   (lambda (a b) (string< (downcase a)
                          (downcase b)))))

(defun ac-go-get-candidates (strings)
  (let ((prop (lambda (entry)
		(let* ((name (nth 0 entry))
		       (summary (nth 1 entry))
		       (symbol (substring summary 0 1)))
		  (propertize name
			      'summary summary
			      'symbol symbol))))
	(split (lambda (strings)
		 (mapcar (lambda (str)
			   (split-string str ",," t))
			 strings))))
    (mapcar prop (funcall split strings))))

(defun ac-go-action ()
  (let ((item (cdr ac-last-completion)))
    (when (stringp item)
      (let ((symbol (get-text-property 0 'summary item)))
        (message "%s" symbol)
        (when (and (featurep 'yasnippet) ac-go-expand-arguments-into-snippets)
          (ac-go-insert-yas-snippet-string symbol))))))

(defun ac-go-insert-yas-snippet-string (s)
  (let ((ret "") (pos (point)) match-res match args)
    (save-match-data
      (setq match-res (string-match "func(." s))
      (when (and match-res (= 0 match-res))
        (setq match (match-string 0 s))
        (unless (string= match "func()")
          (setq args (ac-go-split-args s))
          (dolist (arg args)
            (setq ret (concat ret "${" arg "}, ")))
          (when (> (length ret) 2)
            (setq ret (substring ret 0 (- (length ret) 2)))))
        (setq ret (concat "(" ret ")"))
        (yas-expand-snippet ret pos pos)))))

(defun ac-go-split-args (args-str)
  (let ((cur 5)
        (pre 5)
        (unmatch-l-paren-count 1)
        (args (list))
        c)
    (while (> unmatch-l-paren-count 0)
      (setq c (aref args-str cur))
      (cond ((= ?\( c)
             (setq unmatch-l-paren-count (1+ unmatch-l-paren-count)))
            ((= ?\) c)
             (setq unmatch-l-paren-count (1- unmatch-l-paren-count))
             (when (= 0 unmatch-l-paren-count)
               (push (substring args-str pre cur) args)))
            ((= ?\, c)
             (when (= 1 unmatch-l-paren-count)
               (push (substring args-str pre cur) args)
               (setq cur (+ cur 2))
               (setq pre cur))))
      (setq cur (1+ cur)))
    (nreverse args)))

(defun ac-go-document (item)
  (if (stringp item)
      (let ((s (get-text-property 0 'summary item)))
        (message "%s" s)
        nil)))

(defun ac-go-candidates ()
  (let ((candidates (ac-go-get-candidates
                     (ac-go-format-autocomplete (ac-go-invoke-autocomplete)))))
    (if (equal candidates '("PANIC"))
        (progn
          (message "GOCODE PANIC: Please check your code by \"go build\"")
          nil)
      candidates)))

(defun ac-go-prefix ()
  (or (ac-prefix-symbol)
      (let ((c (char-before)))
        (when (eq ?\. c)
          (point)))))

(ac-define-source go
  '((candidates . ac-go-candidates)
    (candidate-face . ac-candidate-face)
    (selection-face . ac-selection-face)
    (document . ac-go-document)
    (action . ac-go-action)
    (prefix . ac-go-prefix)
    (requires . 0)
    (cache)))

(add-to-list 'ac-modes 'go-mode)

(add-hook 'go-mode-hook #'(lambda ()
                           (add-to-list 'ac-sources 'ac-source-go)))

(provide 'go-autocomplete)
;;; go-autocomplete.el ends here