spring-actuator.el
author Oleksandr Gavenko <gavenkoa@gmail.com>
Mon, 20 Feb 2017 16:04:49 +0200
changeset 1487 d22fade5ae5c
parent 1485 ba6632e1f2f8
child 1491 4a9d4d14b87d
permissions -rw-r--r--
Detect if json-mode available.


(defvar my/spring-actuator-server-history nil)
(defvar my/spring-actuator-last-server "http://localhost:8080")
(defvar my/spring-actuator-path-history nil)
(defvar my/spring-actuator-path-completion
  '("actuator" "auditevents" "autoconfig" "beans" "configprops" "dump" "env" "features" "flyway" "health" "heapdump"
    "info" "jolokia" "liquibase" "logfile" "loggers" "mappings" "metrics" "trace")))

;;;###autoload
(defun my/spring-actuator (server path)
  (interactive (list (read-string "Server: " my/spring-actuator-last-server 'my/spring-actuator-server-history)
                     (completing-read "Path: " my/spring-actuator-path-completion nil nil "" 'my/spring-actuator-path-history)))
  (setq my/spring-actuator-last-server server)
  (let ( (bufname (format "actuator: %s" path)) )
    (when (get-buffer bufname)
      (kill-buffer bufname))
    (switch-to-buffer (url-retrieve-synchronously (format "%s/%s" server path)))
    (rename-buffer bufname)
    (goto-char (point-min))
    (re-search-forward "^$" nil 'move)
    (forward-char)
    (delete-region (point-min) (point))
    (json-pretty-print-buffer)
    (goto-char (point-min))
    (if (fboundp 'json-mode)
        (json-mode)
      (js-mode))
    (setq-local js-indent-level 2)))