Skip to content

Commit

Permalink
Merge pull request #6 from rasensuihei/0.2.4
Browse files Browse the repository at this point in the history
* A network process never querying before exit Emacs.
  • Loading branch information
rasensuihei authored Aug 2, 2019
2 parents fe357cf + 70e749f commit d94bc2b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
## Default key bindings
* `C-c C-c mcf-execute`
* `C-c C-e mcf-execute-at-point`
* `C-c C-r mcf-reload`

---

Expand Down Expand Up @@ -68,9 +69,12 @@ rcon.password=PASSWORD

`mcf-eval` does not block processing, and BODY is evaluated when the server responds.

`mcf-eval` must be nested. If you call consecutively in a loop, the Minecraft RCON server will disconnect the client.

## Changelog
### 0.2.4
* A network process never querying before exit Emacs.
* Highlights valid scoreboard name.
* Display command execution result.
* Added reload command.
### 0.2.3
* Auto connect/Reconnect to RCON server when executes command.
* RCON Command queue feature.
Expand Down
23 changes: 16 additions & 7 deletions mcf-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
(1 font-lock-variable-name-face t)
(2 font-lock-constant-face t))
;; Selector arguments
'("\\([a-zA-Z0-9_]+\\)\s*="
'("\\([a-zA-Z0-9_.+-]+\\)\s*="
(1 font-lock-builtin-face t))
'("\\([,=:]\\)"
(1 font-lock-builtin-face t))
Expand All @@ -95,6 +95,7 @@
(let ((map (make-sparse-keymap)))
(define-key map "\C-c" 'mcf-execute)
(define-key map "\C-e" 'mcf-execute-at-point)
(define-key map "\C-r" 'mcf-reload)
map))

(defvar mcf-mode-map
Expand Down Expand Up @@ -124,11 +125,14 @@
(setq-local comment-start "#")
(setq-local comment-end ""))

(defun mcf-execute (str &optional handler)
"Execute Minecraft command STR. HANDLER is a function for server response handle."
(defun mcf-execute (str)
"Execute Minecraft command STR and display the result in the minibuffer."
(interactive "MCommand: ")
(mcf-rcon-execute-command str handler)
t)
;; (mcf-rcon-execute str handler)
(mcf-rcon-execute str (lambda (payload)
(if (eq payload "")
(message "Minecraft: <empty>")
(message "Minecraft: %s" payload)))))

(defun mcf-execute-at-point ()
"Execute a command at point."
Expand All @@ -137,14 +141,19 @@
(when (string-match "^[# ]*\\(.+\\)$" line)
(mcf-execute (match-string 1 line)))))

(defun mcf-reload ()
"Execute a reload command."
(interactive)
(mcf-execute "reload"))

(defmacro mcf-eval (command &rest args)
"(mcf-eval COMMAND ARGS...)
Evaluate minecraft command with RCON server. A First argument must be payload variable name. (mcf-eval \"COMMAND\" (PAYLOAD) BODY...)"
(declare (indent defun) (debug args))
(if args
`(mcf-rcon-execute-command ,command (lambda (x) (let ((,(caar args) x)) ,@(cdr args))))
`(mcf-rcon-execute-command ,command)))
`(mcf-rcon-execute ,command (lambda (x) (let ((,(caar args) x)) ,@(cdr args))))
`(mcf-rcon-execute ,command)))

(provide 'mcf-mode)
;;; mcf-mode.el ends here
1 change: 1 addition & 0 deletions mcf-rcon.el
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
:buffer mcf-rcon--buffer-name
:address mcf-rcon-address
:service mcf-rcon-port
:noquery t
:nowait t
:filter 'mcf-rcon--filter
:sentinel 'mcf-rcon--sentinel))))
Expand Down

0 comments on commit d94bc2b

Please sign in to comment.