-
Notifications
You must be signed in to change notification settings - Fork 1
/
company-autoconf.el
116 lines (95 loc) · 3.91 KB
/
company-autoconf.el
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
;;; company-autoconf.el --- completion for autoconf script -*- lexical-binding: t; -*-
;; Author: Noah Peart <[email protected]>
;; URL: https://github.com/nverno/company-autoconf
;; Package-Requires:
;; Last modified: <2019-03-07 23:31:52>
;; Copyright (C) 2016, Noah Peart, all rights reserved.
;; Created: 21 September 2016
;; This file is not part of GNU Emacs.
;;
;; 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, 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; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;; Commentary:
;;; Description:
;; Emacs company completion backend for autoconf files. Currently completes
;; for autoconf/automake macros and jumps html documentation for company doc-buffer.
;;; Code:
(eval-when-compile
(require 'cl-lib))
(require 'company)
(defgroup company-autoconf nil
"Company backend for autoconf completion."
:group 'company
:prefix "company-autoconf-")
(defcustom company-autoconf-ignore-case t
"Ignore case when completing."
:group 'company-autoconf
:type 'boolean)
(defvar company-autoconf-data-file "macros.dat")
;; ------------------------------------------------------------
(defvar company-autoconf-urls)
(defvar company-autoconf-dir
(file-name-directory (or load-file-name (buffer-file-name))))
(defun company-autoconf-load (file)
(with-temp-buffer
(insert-file-contents file)
(car (read-from-string (buffer-substring-no-properties (point-min)
(point-max))))))
(defvar company-autoconf-keywords
(let ((data (company-autoconf-load
(expand-file-name company-autoconf-data-file company-autoconf-dir))))
(setq company-autoconf-urls
(cl-loop for url across (cdr (assoc-string "roots" data))
collect (concat (car (split-string url "html_node")) "html_node/")))
(sort
(cl-loop for (k . v) in data
unless (string= k "roots")
do
(put-text-property 0 1 'annot (aref v 1) k)
(put-text-property 0 1 'href (aref v 0) k)
(put-text-property 0 1 'index (aref v 2) k)
collect k)
'string<)))
(defun company-autoconf-prefix ()
(and (memq major-mode '(autoconf-mode m4-mode))
(not (company-in-string-or-comment))
(company-grab-symbol)))
;; retrieval methods
(defun company-autoconf-candidates (arg)
(let ((completion-ignore-case company-autoconf-ignore-case))
(all-completions arg company-autoconf-keywords)))
(defun company-autoconf-annotation (candidate)
(or (get-text-property 0 'annot candidate) ""))
(defun company-autoconf-location (candidate)
"Jump to CANDIDATE documentation in browser."
(when-let* ((idx (get-text-property 0 'index candidate)))
(browse-url
(concat (nth idx company-autoconf-urls)
(get-text-property 0 'href candidate)))))
;;;###autoload
(defun company-autoconf (command &optional arg &rest _args)
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'company-autoconf))
(prefix (company-autoconf-prefix))
(annotation (company-autoconf-annotation arg))
(candidates (company-autoconf-candidates arg))
(doc-buffer (company-autoconf-location arg))
(meta (company-autoconf-annotation arg))
(ignore-case company-autoconf-ignore-case)
(duplicates nil)
(sorted t)))
(provide 'company-autoconf)
;;; company-autoconf.el ends here