Mercurial > hg > Members > kokubo > emacs
comparison .emacs.d/haskell-mode/haskell-package.el @ 0:2764b4f45f9f
1st commit
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 21 Apr 2014 04:30:59 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2764b4f45f9f |
---|---|
1 ;;; haskell-package.el --- Interface for working with Cabal packages | |
2 | |
3 ;; Copyright (C) 2011 Chris Done | |
4 | |
5 ;; Author: Chris Done <chrisdone@gmail.com> | |
6 | |
7 ;; This file is not part of GNU Emacs. | |
8 | |
9 ;; This file is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 3, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; This file is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
22 ;; Boston, MA 02110-1301, USA. | |
23 | |
24 ;;; Commentary: | |
25 | |
26 ;;; Todo: | |
27 | |
28 ;;; Code: | |
29 | |
30 (with-no-warnings (require 'cl)) | |
31 | |
32 ;; Dynamically scoped variables. | |
33 ;; TODO What actually sets this? | |
34 (defvar haskell-config-use-cabal-dev) | |
35 | |
36 ;; (defun haskell-package-conf-path-get (&optional project) | |
37 ;; "Gets the user conf or the cabal-dev conf. Get the global conf elsewhere." | |
38 ;; (if haskell-config-use-cabal-dev | |
39 ;; (if project | |
40 ;; (let* ((cabal-path (haskell-project-cabal-dir project))) | |
41 ;; (format "%scabal-dev/packages-%s.conf/" | |
42 ;; (if (string-match "/$" cabal-path) | |
43 ;; cabal-path | |
44 ;; (concat cabal-path "/")) | |
45 ;; (haskell-ghc-version))) | |
46 ;; (haskell-package-conf-user-path-get)) | |
47 ;; (haskell-package-conf-user-path-get))) | |
48 | |
49 (defun haskell-package-conf-user-path-get () | |
50 "Get the user conf path." | |
51 (let ((out (shell-command-to-string "ghc-pkg --user list no-results-please"))) | |
52 (string-match "\n\\(.*\\):\n" out) (match-string 1 out))) | |
53 | |
54 (defun haskell-package-conf-global-path-get () | |
55 "Get the global conf path." | |
56 (let ((out (shell-command-to-string "ghc-pkg --global list no-results-please"))) | |
57 (string-match "\n\\(.*\\):\n" out) (match-string 1 out))) | |
58 | |
59 (defun haskell-package-get-all (conf) | |
60 "Get all package descriptions for the given `conf'." | |
61 (let ((all (shell-command-to-string (format "ghc-pkg -f %s dump" conf)))) | |
62 (mapcar (lambda (text) | |
63 (haskell-package-parse text)) | |
64 (split-string all "\n---\n")))) | |
65 | |
66 (defun haskell-package-get (conf name version) | |
67 "Get a package description for the given `name' and `version' in the given `conf'." | |
68 (haskell-package-parse | |
69 (shell-command-to-string | |
70 (format "ghc-pkg -f %s describe %s-%s" | |
71 conf | |
72 name | |
73 version)))) | |
74 | |
75 (defstruct haskell-package "Haskell package object.") | |
76 | |
77 (defun haskell-package-parse (text) | |
78 "Parse a package into a package object." | |
79 (let ((pkg (haskell-package-read-description text))) | |
80 (make-haskell-package | |
81 :name (cdr (assoc "name" pkg)) | |
82 :version (cdr (assoc "version" pkg)) | |
83 :id (cdr (assoc "id" pkg)) | |
84 :license (cdr (assoc "license" pkg)) | |
85 :copyright (cdr (assoc "copyright" pkg)) | |
86 :maintainer (cdr (assoc "maintainer" pkg)) | |
87 :stability (cdr (assoc "stability" pkg)) | |
88 :homepage (cdr (assoc "homepage" pkg)) | |
89 :package-url (cdr (assoc "package-url" pkg)) | |
90 :description (cdr (assoc "description" pkg)) | |
91 :categories (cdr (assoc "category" pkg)) | |
92 :authors (cdr (assoc "author" pkg)) | |
93 :is-exposed (equal "True" (cdr (assoc "exposed" pkg))) | |
94 :exposed-modules (split-string (or (cdr (assoc "exposed-modules" pkg)) "") | |
95 "[\n ]") | |
96 :hidden-modules (split-string (or (cdr (assoc "hidden-modules" pkg)) "") | |
97 "[\n ]") | |
98 :imports-dirs (cdr (assoc "imports-dirs" pkg)) | |
99 :library-dirs (cdr (assoc "library-dirs" pkg)) | |
100 :haskell-libraries (cdr (assoc "haskell-libraries" pkg)) | |
101 :extra-libraries (cdr (assoc "extra-libraries" pkg)) | |
102 :extra-ghci-libraries (cdr (assoc "extra-ghci-libraries" pkg)) | |
103 :include-dirs (cdr (assoc "include-dirs" pkg)) | |
104 :includes (cdr (assoc "includes" pkg)) | |
105 :depends (cdr (assoc "depends" pkg)) | |
106 :hugs-options (cdr (assoc "hugs-options" pkg)) | |
107 :cc-options (cdr (assoc "cc-options" pkg)) | |
108 :ld-options (cdr (assoc "ld-options" pkg)) | |
109 :framework-dirs (cdr (assoc "framework-dirs" pkg)) | |
110 :frameworks (cdr (assoc "frameworks" pkg)) | |
111 :haddock-interfaces (cdr (assoc "haddock-interfaces" pkg)) | |
112 :haddock-html (cdr (assoc "haddock-html" pkg))))) | |
113 | |
114 (defun haskell-package-read-description (text) | |
115 "Return an association list of key-values from a pkg description string." | |
116 (let* ((marked (replace-regexp-in-string | |
117 "\n\\([^ ]\\)" | |
118 (lambda (match) | |
119 (concat "\n:" (substring match 1))) | |
120 text)) | |
121 (alist (mapcar 'haskell-package-key-value | |
122 (split-string marked "\n:")))) | |
123 alist)) | |
124 | |
125 (defun haskell-package-key-value (entry) | |
126 "Return a (key . value) pair from an entry." | |
127 (let ((key-values (split-string entry ": "))) | |
128 (if (listp key-values) | |
129 (cons (car key-values) | |
130 (replace-regexp-in-string | |
131 "\n[ ]*" | |
132 " " | |
133 (mapconcat 'identity (cdr key-values) ": "))) | |
134 key-values))) | |
135 | |
136 (defun haskell-package-list-get (conf) | |
137 "Get the list of packages in the given config." | |
138 (haskell-package-list-parse | |
139 (shell-command-to-string | |
140 (format "ghc-pkg -f %s list" | |
141 conf)))) | |
142 | |
143 (defun haskell-package-list-parse (text) | |
144 "Parse the list of installed packges." | |
145 (let* ((lines (split-string text "\n "))) | |
146 (mapcar | |
147 (lambda (line) | |
148 (string-match "^{?\\([a-zA-Z0-9-_]+\\)-\\([0-9.]+\\)}?$" line) | |
149 (cons (match-string 1 line) (match-string 2 line))) | |
150 (delete-if | |
151 (lambda (line) | |
152 (not (string-match "^{?[a-zA-Z0-9-_]+-[0-9.]+}?$" line))) | |
153 lines)))) | |
154 | |
155 (provide 'haskell-package) | |
156 | |
157 ;; Local Variables: | |
158 ;; byte-compile-warnings: (not cl-functions) | |
159 ;; End: | |
160 | |
161 ;;; haskell-package.el ends here |