Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Use dash.el #103

Merged
merged 1 commit into from
Nov 26, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 41 additions & 38 deletions elisp/hie.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
;;; hie.el --- Haskell IDE Engine process -*- lexical-binding: t -*-

;; Copyright (c) 2015 Haskell Ide Contributors
;; Package-Requires: ((dash "2.12.1"))

;; See LICENSE for details.

Expand Down Expand Up @@ -127,11 +128,11 @@ by `hie-handle-message'."
Items of the form '(\"key\" . ()) will be removed from assoc list
JSON. Returns the new list."
(if (listp json)
(mapcar (lambda (item)
(if (consp item)
(cons (car item) (hie-remove-alist-null-values (cdr item)))
item))
(cl-remove-if (lambda (item) (and (consp item) (null (cdr item)))) json))
(-map (lambda (item)
(if (consp item)
(cons (car item) (hie-remove-alist-null-values (cdr item)))
item))
(cl-remove-if (lambda (item) (and (consp item) (null (cdr item)))) json))
json))

(defun hie-prepare-json (json)
Expand All @@ -152,12 +153,13 @@ association lists and count on HIE to use default values there."
(message (format "%s" json)))

(defun hie-handle-command-detail (json)
(let ((context
(hie-get-context (cdr (assq 'contexts json)))))
(-let* (((&alist 'contexts contexts 'name command-name 'plugin_name plugin-name) json)
(context
(hie-get-context contexts)))
(setq hie-process-handle-message
#'hie-handle-message)
(hie-post-message
`(("cmd" . ,(hie-format-cmd (cons (cdr (assq 'plugin_name json)) (cdr (assq 'name json)))))
`(("cmd" . ,(hie-format-cmd (cons plugin-name command-name)))
("params" . ,context)))))

(defun hie-format-cmd (cmd)
Expand All @@ -184,29 +186,30 @@ association lists and count on HIE to use default values there."

(defun hie-handle-first-plugins-command (json)
"Handle first plugins call."
(let ((menu-items
(mapcar
(lambda (plugin)
(cons (symbol-name (car plugin))
(mapcar
(lambda (command)
(vector (cdr (assq 'ui_description command))
(intern (concat "hie-"
(symbol-name (car plugin))
"-"
(cdr (assq 'name command))))))
(cdr plugin))))
(cdr (assq 'plugins json))))
(command-names
(mapcar
(lambda (plugin)
(cons (car plugin)
(mapcar
(lambda (command)
(cdr (assq 'name command)))
(cdr plugin))))
(cdr (assq 'plugins json)))))
(setq hie-plugins (cdr (assq 'plugins json)))
(-let* (((&alist 'plugins plugins) json)
(menu-items
(-map
(-lambda ((plugin-name . commands))
(cons (symbol-name plugin-name)
(-map
(-lambda ((&alist 'name name 'ui_description description))
(vector description
(intern (concat "hie-"
(symbol-name plugin-name)
"-"
name))))
commands)))
plugins))
(command-names
(-map
(-lambda ((plugin-name . commands))
(cons plugin-name
(-map
(-lambda ((&alist 'name name))
name)
commands)))
plugins)))
(setq hie-plugins plugins)
(hie-create-all-commands command-names)
(easy-menu-define hie-menu hie-mode-map
"Menu for Haskell IDE Engine"
Expand All @@ -219,13 +222,13 @@ association lists and count on HIE to use default values there."

(defun hie-create-all-commands (command-names)
(eval `(progn
,@(apply 'append (mapcar
(lambda (plugin)
(mapcar
(lambda (command)
(hie-create-command (car plugin) command))
(cdr plugin)))
command-names)))))
,@(-mapcat
(-lambda ((plugin-name . commands))
(-map
(-lambda (command)
(hie-create-command plugin-name command))
commands))
command-names))))

(define-minor-mode hie-mode
"Haskell IDE Engine mode.
Expand Down