1
0
Derivar 1

Break the rigel cube into autoload sections

Este cometimento está contido em:
Sameer Rahmani 2022-04-15 23:13:54 +01:00
ascendente 699bc88830
cometimento e4249444f8
2 ficheiros modificados com 132 adições e 29 eliminações

Ver ficheiro

@ -35,36 +35,23 @@ functions in `fg42/rigel/` namespace. For example `fg42/rigel/read` function."
:flag rigel
:flag-default t)
(autoload-cube
'fg42/rigel/read
"rigel/core.el"
"Send the given text to the Rigel server to read it out load" t)
(autoload-cube
'fg42/rigel/read-region
"rigel/core.el"
"Send the text of selected region to the Rigel server to read it out load" t)
(autoload-cube
'fg42/rigel/read-clipboard
"rigel/core.el"
"Send the text from the clipboadr to the Rigel server to read it out load" t)
(defun fg42/rigel/-sentinel (process event)
(message "[Rigel] %s" event))
(defun fg42/rigel/read (txt)
(interactive "sRead: ")
(let ((proc (make-network-process
:name "rigel-client"
:type nil
:server nil
:host (or (plist-get fg42/rigel-cube-params :host) "127.0.0.1")
:service (or (plist-get fg42/rigel-cube-params :port) "6666")
:nowait t
:buffer (get-buffer-create "*rigel*")
:sentinel 'fg42/rigel/-sentinel
)))
(process-send-string proc txt)
(process-send-eof proc)
(stop-process proc)))
(defun fg42/rigel/read-region (beg end)
(interactive (if (use-region-p)
(list (region-beginning) (region-end))
(list nil nil)))
(fg42/rigel/read
(if (and beg end) (buffer-substring-no-properties beg end) "")))
(defun fg42/rigel/read-clipboard ()
(interactive)
(fg42/rigel/read
(or (current-kill 0) ""))))
(message "[Rigel] %s" event)))
(provide 'cubes/rigel)

116
core/cubes/rigel/core.el Ficheiro normal
Ver ficheiro

@ -0,0 +1,116 @@
;;; RigelCube --- Rigel client for FG42 -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2010-2021 Sameer Rahmani & Contributors
;;
;; Author: Sameer Rahmani <lxsameer@gnu.org>
;; URL: https://ziglab.com/FG42/FG42
;; Version: 3.0.0
;;
;; 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:
;;; Code:
(require 'bindat)
(eval-when-compile
(defvar fg42/rigel-cube-params))
(defconst fg42/rigel/protocol
(bindat-type (len uint 32) (payload str (+ 32 len))))
(defvar fg42/rigel/client-process nil
"The process for the client.")
(defvar fg42/rigel/host (or (plist-get fg42/rigel-cube-params :host) "127.0.0.1")
"The hostname or ip address of the Rigel server.")
(defvar fg42/rigel/port (or (plist-get fg42/rigel-cube-params :port) "6666")
"The port number of the target Rigel server.")
(defun fg42/rigel/-pack-struct (str)
"Pack the given STR in an alist representing a message."
(list (cons 'len (length (eval str))) (cons 'payload (eval str))))
(defun fg42/rigel/-pack (str)
"Pack the give STR into binary format according to the `fg42/rigel/protocol'
protocol."
(bindat-pack fg42/rigel/protocol (fg42/rigel/-pack-struct str)))
(defun fg42/rigel/-sentinel (process event)
(message "[Rigel] %s: %s" process event))
(defun fg42/rigel/-connect ()
(when (null fg42/rigel/client-process)
(message "[Rigel] Connecting to server at %s:%s" fg42/rigel/host fg42/rigel/port)
(setq fg42/rigel/client-process
(make-network-process
:name "rigel-client"
:type nil
:server nil
:host fg42/rigel/host
:service fg42/rigel/port
:nowait t
:buffer (get-buffer-create "*Rigel*")
:sentinel 'fg42/rigel/-sentinel))))
(defun fg42/rigel/close ()
"Shutdown the Rigel client"
(interactive)
(message "[Rigel] Status: %s" (process-status "rigel-client"))
(when (process-status "rigel-client")
(process-send-string fg42/rigel/client-process (fg42/rigel/-pack "//close"))
(stop-process fg42/rigel/client-process))
(setq fg42/rigel/client-process nil)
(kill-buffer "*Rigel*"))
(defun fg42/rigel/read (txt)
"Send the given text to the Rigel server to read it out load"
(interactive "sRead: ")
;; (let ((status (process-status "rigel-client")))
;; (message "[Rigel] Status: %s" status)
;; (cond
;; ((string= status "stop")
;; (continue-process "rigel-client"))
;; ((and (string= status "connect")
;; (string= status "open")) nil)
;; (t (fg42/rigel/-connect))))
(fg42/rigel/-connect)
(process-send-string fg42/rigel/client-process (fg42/rigel/-pack txt))
;;(process-send-eof fg42/rigel/client-process)
;; (stop-process fg42/rigel/client-process)
)
(defun fg42/rigel/read-region (beg end)
"Send the text of selected region to the Rigel server to read it out load"
(interactive (if (use-region-p)
(list (region-beginning) (region-end))
(list nil nil)))
(fg42/rigel/read
(if (and beg end) (buffer-substring-no-properties beg end) "")))
(defun fg42/rigel/read-clipboard ()
"Send the text from the clipboadr to the Rigel server to read it out load"
(interactive)
(fg42/rigel/read
(or (current-kill 0) "")))
(provide 'cubes/rigel/core)
;;; core.el ends here