-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlemmington.el
122 lines (102 loc) · 3.63 KB
/
lemmington.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
117
118
119
120
121
122
;;; lemmington.el --- RPC Emacs server -*- lexical-binding: t; -*-
;; Copyright (C) 2023 Fermin Munoz
;; Author: Fermin Munoz
;; Maintainer: Fermin Munoz <[email protected]>
;; Created: 25 June 2023
;; Version: 0.0.1
;; Keywords: tools,languages
;; URL: https://github.com/lem-project/lemmington.git
;; Package-Requires: ((emacs "27.1")(porthole "0.3.0")(elisp-refs "1.6"))
;; License: GPL-3.0-or-later
;; 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 <https://www.gnu.org/licenses/>.
;;; Code:
;;;; The requires
(require 'cl-lib)
(require 'porthole)
(require 'elisp-refs)
(defgroup lemmington nil
"Lemmington group."
:group 'lemmington
:link '(url-link :tag "Repository" "https://github.com/lem-project/lemmington.git"))
(defcustom lemmington-user-export-functions nil
"User defined functions to export."
:group 'lemmington
:type 'list)
(cl-defun lemmington-start-server (&key
(name "lemmington-server")
(port 55486)
(username "lem")
(password "lem"))
"Start the porthole server.
Optionally, you can set as a key argument:
NAME : name of the server.
PORT: port of the server.
USERNAME: username for the basic-auth.
PASSWORD: password for the basic-auth."
(porthole-start-server-advanced
name
:port port
:username username
:password password
:publish-port nil
:publish-username t
:publish-password t))
(cl-defun lemmington-get-completion (prefix)
"Return a list of symbols with PREFIX as prefix."
(elisp-refs--filter-obarray (lambda (i)
(string-prefix-p prefix (format "%s" i) t))))
;;TODO: Fix this ugly ignore errors
(cl-defun lemmington-symbol-location (symbol)
"Return a a list of (file absolute-position) of SYMBOL."
(ignore-errors
(let ((symbol-intern (intern-soft symbol))
symbol-info)
(cond
((functionp symbol-intern)
(setf symbol-info
(find-definition-noselect symbol-intern nil)))
((boundp symbol-intern)
(setf symbol-info
(find-definition-noselect symbol-intern 'defvar)))
(t
(cl-return-from lem-symbol-location
nil)))
(list (buffer-file-name (car symbol-info))
(cdr symbol-info)))))
(cl-defun lemmington-symbol-documentation (symbol)
"Return SYMBOL documentation."
(let ((symbol-intern (intern-soft symbol)))
(cond
((functionp symbol-intern)
(documentation symbol-intern))
((boundp symbol-intern)
(documentation-property symbol-intern 'variable-documentation))
(t
(cl-return-from lem-symbol-documentation
nil)))))
(cl-defun lemmington-exported-functions ()
(append *lemmington-export-functions*
lemmington-user-export-functions))
(defvar *lemmington-export-functions*
'(lemmington-get-completion
lemmington-symbol-location
lemmington-symbol-documentation
lemmington-exported-functions))
(cl-defun lemmington-export-functions (&key
(server "lemmington-server")
(functions *lemmington-export-functions*))
"Export FUNCTIONS to SERVER."
(mapcar (lambda (fname)
(porthole-expose-function server fname))
(append functions lemmington-user-export-functions)))
(provide 'lemmington)
;;; lemmington.el ends here