[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode 9359c7b 349/385: cl-loop
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode 9359c7b 349/385: cl-loop |
Date: |
Wed, 6 Oct 2021 00:00:02 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit 9359c7b1bddd63d1b2abb8be1599aa597b2de8e1
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
cl-loop
---
haskell-tng-hsinspect.el | 157 +++++++++++++++++++++++------------------------
1 file changed, 76 insertions(+), 81 deletions(-)
diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el
index e8c6120..8227d09 100644
--- a/haskell-tng-hsinspect.el
+++ b/haskell-tng-hsinspect.el
@@ -191,7 +191,8 @@ Respects the `C-u' cache invalidation convention."
(setq sym (match-string 2 sym)))
(let ((qual_ (car (rassoc qual haskell-tng-hsinspect-as))))
- (if (haskell-tng--hsinspect-check-fqn-import index qual_ sym)
+ (if (when qual_
+ (haskell-tng--hsinspect-check-fqn-import index qual_ sym))
(haskell-tng--hsinspect-import-symbol index qual_ qual)
(when-let (hit (haskell-tng--hsinspect-import-popup index sym))
(let* ((module (alist-get 'module hit))
@@ -225,52 +226,51 @@ Respects the `C-u' cache invalidation convention."
(defun haskell-tng--hsinspect-extract-imports (index module &optional as sym)
"Calculates the imports from INDEX that are implied by MODULE AS and SYM."
- ;; TODO a nested seq-mapcat threaded syntax
(if sym
`(((local . ,sym) (full . ,(concat module "." sym))))
- (seq-mapcat
- (lambda (pkg-entry)
- (seq-mapcat
- (lambda (module-entry)
- (when (equal module (alist-get 'module module-entry))
- (seq-mapcat
- (lambda (entry)
- (let* ((name (alist-get 'name entry))
- (type (alist-get 'type entry))
- (id (pcase (alist-get 'class entry)
- ((or 'id 'con 'pat) name)
- ('tycon type)))
- (full (concat module "." id)))
- (if as
- `(((qual . ,(concat as "." id))
- (full . ,full)))
- `(((local . ,id)
- (full . ,full))))))
- (alist-get 'ids module-entry))))
- (alist-get 'modules pkg-entry)))
- index)))
+ (cl-loop
+ for pkg-entry in index
+ append
+ (cl-loop
+ for module-entry in (alist-get 'modules pkg-entry)
+ when (equal module (alist-get 'module module-entry))
+ append
+ (cl-loop
+ for entry in (alist-get 'ids module-entry)
+ collect
+ (let* ((name (alist-get 'name entry))
+ (type (alist-get 'type entry))
+ (id (pcase (alist-get 'class entry)
+ ((or 'id 'con 'pat) name)
+ ('tycon type)))
+ (full (concat module "." id)))
+ (if as
+ `((qual . ,(concat as "." id))
+ (full . ,full))
+ `((local . ,id)
+ (full . ,full)))))))))
(defun haskell-tng--hsinspect-check-fqn-import (index module sym)
"Checks if an FQN exists"
- ;; TODO a nested seq-mapcat threaded syntax
- (when module
- (seq-mapcat
- (lambda (pkg-entry)
- (seq-mapcat
- (lambda (module-entry)
- (when (equal module (alist-get 'module module-entry))
- (seq-mapcat
- (lambda (entry)
- (let* ((name (alist-get 'name entry))
- (type (alist-get 'type entry))
- (id (pcase (alist-get 'class entry)
- ((or 'id 'con 'pat) name)
- ('tycon type))))
- (when (equal sym id)
- `((,(alist-get 'srcid pkg-entry))))))
- (alist-get 'ids module-entry))))
- (alist-get 'modules pkg-entry)))
- index)))
+ (block nested
+ (cl-loop
+ for pkg-entry in index
+ do
+ (cl-loop
+ for module-entry in (alist-get 'modules pkg-entry)
+ when (equal module (alist-get 'module module-entry))
+ do
+ (cl-loop
+ for entry in (alist-get 'ids module-entry)
+ do
+ (let* ((name (alist-get 'name entry))
+ (type (alist-get 'type entry))
+ (id (pcase (alist-get 'class entry)
+ ((or 'id 'con 'pat) name)
+ ('tycon type))))
+ (when (equal sym id)
+ (return-from nested
+ `(,(alist-get 'srcid pkg-entry))))))))))
(defun haskell-tng--hsinspect-return-type (type)
(car
@@ -298,18 +298,16 @@ Respects the `C-u' cache invalidation convention."
nil if nothing was found.
If SRCID is nil then the first matching MODULE is used."
- ;; TODO seq-findmap as an alternative to (car (seq-mapcat ...)) or
throw/catch
- (catch 'found
- (seq-do
- (lambda (pkg-entry)
- (when (or (null srcid) (equal srcid (alist-get 'srcid pkg-entry)))
- (seq-do
- (lambda (module-entry)
- (when (equal module (alist-get 'module module-entry))
- (throw 'found (cons pkg-entry module-entry))))
- (alist-get 'modules pkg-entry))))
- index)
- nil))
+ (block nested
+ (cl-loop
+ for pkg-entry in index
+ when (or (null srcid) (equal srcid (alist-get 'srcid pkg-entry)))
+ do
+ (cl-loop
+ for module-entry in (alist-get 'modules pkg-entry)
+ when (equal module (alist-get 'module module-entry))
+ do
+ (return-from nested (cons pkg-entry module-entry))))))
(defun haskell-tng--hsinspect-follow (index srcid module name)
"Follow re-exports of MODULE to find where it was originally defined.
@@ -352,34 +350,31 @@ ability to follow any further."
"Return an list of alists with keys: module, name, type.
When using hsinspect-0.0.8, also: class, export, flavour.
When using hsinspect-0.0.9, also: srcid."
- ;; TODO threading/do syntax
- ;; TODO alist variable binding like RecordWildcards
- (seq-mapcat
- (lambda (pkg-entry)
+ (cl-loop
+ for pkg-entry in index
+ append
+ (cl-loop
+ for module-entry in (alist-get 'modules pkg-entry)
+ append
+ (cl-loop
+ for entry in (alist-get 'ids module-entry)
+ append
(let ((srcid (alist-get 'srcid pkg-entry))
- (modules (alist-get 'modules pkg-entry)))
- (seq-mapcat
- (lambda (module-entry)
- (let ((module (alist-get 'module module-entry))
- (ids (alist-get 'ids module-entry)))
- (seq-mapcat
- (lambda (entry)
- (let ((name (alist-get 'name entry))
- (type (alist-get 'type entry))
- (class (alist-get 'class entry))
- (export (alist-get 'export entry))
- (flavour (alist-get 'flavour entry)))
- (when (or (equal name sym) (equal type sym))
- `(((srcid . ,srcid)
- (module . ,module)
- (name . ,name)
- (type . ,type)
- (class . ,class)
- (export . ,export)
- (flavour . ,flavour))))))
- ids)))
- modules)))
- index))
+ (module (alist-get 'module module-entry))
+ (name (alist-get 'name entry))
+ (type (alist-get 'type entry))
+ (class (alist-get 'class entry))
+ (export (alist-get 'export entry))
+ (flavour (alist-get 'flavour entry)))
+ ;; TODO alist variable binding like RecordWildcards
+ (when (or (equal name sym) (equal type sym))
+ `(((srcid . ,srcid)
+ (module . ,module)
+ (name . ,name)
+ (type . ,type)
+ (class . ,class)
+ (export . ,export)
+ (flavour . ,flavour)))))))))
(defun haskell-tng--hsinspect-symbol-at-point ()
"A `symbol-at-point' that includes FQN parts."
- [nongnu] elpa/haskell-tng-mode dbb2b7a 350/385: block / return-from instead of catch / throw, (continued)
- [nongnu] elpa/haskell-tng-mode dbb2b7a 350/385: block / return-from instead of catch / throw, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode d611f0b 322/385: thots, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode a717a50 331/385: allow workflow with qualified imports as default, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 70e649b 330/385: import qualified is even smarter, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 5a064fd 328/385: hypen prefix asks to qualify the import, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode c42b5c5 338/385: use url-copy-path instead of shelling out, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 8405852 351/385: document bugs and ideas, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode f429326 327/385: thots, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 8bb3c34 363/385: the in-memory cache doesn't have to cache nil, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode f5977b6 339/385: bugfix for source downloading, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 9359c7b 349/385: cl-loop,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode f5d76fc 348/385: tidy docs, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 3b37524 360/385: bugfix for qualified imports when the cache was bad, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode fe2b164 372/385: fix the build, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 63225d5 374/385: use .ghc.path to find hsinspect, build tool agnostic, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 3d1122b 116/385: notes on regexps, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode c3793b2 176/385: canonical until macro, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode b7cb5b9 214/385: starting to create imenu, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 5306ae2 217/385: fix type faces with constraints, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 5f81d6b 219/385: bump python version, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 8f4d7fc 225/385: advice around smartparens workaround, ELPA Syncer, 2021/10/06