[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/names 82f12ac 17/44: Merge branch 'elpa' into dev
From: |
Stefan Monnier |
Subject: |
[elpa] externals/names 82f12ac 17/44: Merge branch 'elpa' into dev |
Date: |
Sat, 27 Mar 2021 14:40:11 -0400 (EDT) |
branch: externals/names
commit 82f12ac63539439987b1228307f29fdd27ec5902
Merge: ca0f397 7020c67
Author: Artur Malabarba <bruce.connor.am@gmail.com>
Commit: Artur Malabarba <bruce.connor.am@gmail.com>
Merge branch 'elpa' into dev
---
TheNittyGritty.org | 35 +++++++++++++++++++++++++++++++++++
UsageExample.org | 5 ++++-
names-dev.el | 34 ++++++++++++++++++++++++----------
names.el | 27 +++++++++++++++++++++++++--
4 files changed, 88 insertions(+), 13 deletions(-)
diff --git a/TheNittyGritty.org b/TheNittyGritty.org
index 78bf88b..84bf6b8 100644
--- a/TheNittyGritty.org
+++ b/TheNittyGritty.org
@@ -139,6 +139,41 @@ need to worry about, it should just do what you expect
from it.
This is only relevant if you write your own macros. If you do,
remember to add a debug declaration in them.
+
+*** The theading macros (~->~ and ~-->~)
+
+The threading macros would require special treatment to namespace
+correctly. However, you can use the ~:functionlike-macros~ keyword to
+tell *Names* to treat them as regular functions.
+
+For example, in the following snippet:
+#+BEGIN_SRC emacs-lisp
+(require 'dash)
+(define-namespace foo-
+:functionlike-macros (-> ->>)
+
+(defvar var nil)
+(defun fun (x &optional y)
+ (concat x y))
+
+(-> "some string"
+ (fun var)
+ fun)
+)
+#+END_SRC
+the ~(fun var)~ part would be namespaced prefectly fine (~fun~ and
+~var~ will be identified as a function and variable respectively),
+because it looks like a regular function call. However, the second use
+of ~fun~ will not be correctly namespaced, because that ~fun~ looks
+like a variable.
+
+In other words, you should use these macros like this instead:
+#+BEGIN_SRC emacs-lisp
+(-> "some string"
+ (fun var)
+ (fun))
+#+END_SRC
+
** Accessing Global Symbols
If one of your definitions shadows a global definition, you can still
access it by prefixing it with =::=.
diff --git a/UsageExample.org b/UsageExample.org
index b27160e..5730966 100644
--- a/UsageExample.org
+++ b/UsageExample.org
@@ -14,7 +14,10 @@ The important items are already listed in the Readme:
;;; Code:
-;; `define-namespace' is autoloaded, so there's no need to require `names'.
+;; `define-namespace' is autoloaded, so there's no need to require
+;; `names'. However, requiring it here means it will also work for
+;; people who don't install through package.el.
+(eval-when-compile (require 'names))
;;;###autoload
(define-namespace example-
diff --git a/names-dev.el b/names-dev.el
index 4efc12e..0c2dc20 100644
--- a/names-dev.el
+++ b/names-dev.el
@@ -62,11 +62,11 @@
(defmacro names-print (name &rest forms)
"Return the expanded results of (namespace NAME :global :verbose FORMS).
Ideal for determining why a specific form isn't being parsed
-correctly."
+correctly. You may need to set `eval-expression-print-level' and
+`eval-expression-print-length' to nil in order to see your full
+expansion."
(declare (indent (lambda (&rest x) 0)) (debug 0))
- `(let ((eval-expression-print-level (max eval-expression-print-level 300))
- (eval-expression-print-length (max eval-expression-print-length 300)))
- (macroexpand '(define-namespace ,name :global :verbose ,@forms))))
+ `(define-namespace ,name :global :verbose ,@forms))
(defvar names-font-lock
'(("^:autoload\\_>" 0 'font-lock-warning-face prepend)
@@ -152,12 +152,17 @@ If KILL is non-nil, kill the temp buffer afterwards."
(kill-buffer b))))))
(defun names--top-of-namespace ()
- ""
- (progn
- (beginning-of-defun)
- (ignore-errors
- (backward-up-list)
- (names--looking-at-namespace))))
+ "Move to the top of current namespace, and return non-nil.
+If not inside a namespace, return nil and don't move point."
+ (let ((top (save-excursion
+ (beginning-of-defun)
+ (ignore-errors
+ (backward-up-list))
+ (when (names--looking-at-namespace)
+ (point)))))
+ (when top
+ (goto-char top)
+ t)))
(defun names-eval-defun (edebug-it)
"Identical to `eval-defun', except it works for forms inside namespaces.
@@ -204,6 +209,15 @@ Argument EVAL-LAST-SEXP-ARG-INTERNAL is the same as
`eval-print-last-sexp'."
;; (pp (symbol-function 'names--preceding-sexp-original) (current-buffer))
+(defun names-pprint ()
+ "Pretty-print an expansion of the namespace around point."
+ (interactive)
+ (save-excursion
+ (when (names--top-of-namespace)
+ (let ((ns (cdr (read (current-buffer)))))
+ (pp-macroexpand-expression
+ (macroexpand (cons 'names-print ns)))))))
+
;;; Find stuff
(require 'find-func nil t)
diff --git a/names.el b/names.el
index 4cd23a1..7ae9521 100644
--- a/names.el
+++ b/names.el
@@ -182,6 +182,22 @@ Is only non-nil if the :group keyword is passed to
`define-namespace'.")
"The version number given by :version.
Used to define a constant and a command.")
+(defvar names--functionlike-macros nil
+ "Function-like macros, even if their debug-spec says otherwise.
+When expanding the namespace, these macros will be treated
+exactly like functions. This means that their contents will be
+namespaced like regular function arguments.
+
+To add macros to this list, pass the :functionlike-macros keyword
+to your namespace along with a list of macro names (as unquoted
+symbols).
+Example:
+
+ (define-namespace foo-
+ :functionlike-macros (-> ->> thread-first thread-last)
+ ;; Rest of code
+ )")
+
(defconst names--keyword-list
`((:group
1 ,(lambda (x)
@@ -240,6 +256,12 @@ needed by the :version and :group keywords.")
(format "\\`%s" (regexp-quote val)))))
"Change the value of the `names--protection' variable.")
+ (:functionlike-macros
+ 1
+ ,(lambda (x) (setq names--functionlike-macros
+ (append x names--functionlike-macros)))
+ "A list of values to be appended to `names--functionlike-macros'.")
+
(:no-let-vars
0 nil
"Indicates variables assigned in let-bind are NOT candidates for
namespacing.")
@@ -407,6 +429,7 @@ See `define-namespace' for more information."
(names--remove-namespace-from-list
(names--filter-if-bound byte-compile-macro-environment (lambda
(x) (not (names--compat-macrop x))))
(names--filter-if-bound byte-compile-function-environment
(lambda (x) (not (names--compat-macrop x))))))
+ (names--functionlike-macros names--functionlike-macros)
names--keywords names--local-vars key-and-args
names--version names--package names--group-parent)
;; Read keywords
@@ -742,7 +765,6 @@ returns nil."
(and (names--keyword :global)
(boundp (names--prepend sbl))))))
-;;; This is calling edebug even on `when' and `unless'
(defun names--args-of-function-or-macro (function args macro)
"Namespace FUNCTION's arguments ARGS, with special treatment if MACRO is
non-nil."
(if macro
@@ -750,7 +772,8 @@ returns nil."
(names--verbose (eq function 'push)))
(names--message "Edebug-spec of `%s' is %s" function it)
;; Macros where we evaluate all arguments are like functions.
- (if (equal it t)
+ (if (or (equal it t)
+ (memq function names--functionlike-macros))
(names--args-of-function-or-macro function args nil)
;; Macros where nothing is evaluated we can just return.
(if (equal it 0)
- [elpa] externals/names 2b24400 33/44: Merge branch 'elpa' into dev, (continued)
- [elpa] externals/names 2b24400 33/44: Merge branch 'elpa' into dev, Stefan Monnier, 2021/03/27
- [elpa] externals/names 34339b6 36/44: Merge pull request #25 from yurrriq/patch-1, Stefan Monnier, 2021/03/27
- [elpa] externals/names 65b577b 40/44: Merge pull request #28 from tarsius/master, Stefan Monnier, 2021/03/27
- [elpa] externals/names 65cb3f7 34/44: Merge branch 'dev', Stefan Monnier, 2021/03/27
- [elpa] externals/names 7a6692a 04/44: Merge branch 'elpa' into dev, Stefan Monnier, 2021/03/27
- [elpa] externals/names 2a5b21c 05/44: Merge branch 'elpa', Stefan Monnier, 2021/03/27
- [elpa] externals/names ca0f397 15/44: Travis badge, Stefan Monnier, 2021/03/27
- [elpa] externals/names 1587d24 29/44: Stop testing 23.4, Stefan Monnier, 2021/03/27
- [elpa] externals/names 097dc46 30/44: Update usage example, Stefan Monnier, 2021/03/27
- [elpa] externals/names 374c903 31/44: Merge branch 'elpa' into dev, Stefan Monnier, 2021/03/27
- [elpa] externals/names 82f12ac 17/44: Merge branch 'elpa' into dev,
Stefan Monnier <=
- [elpa] externals/names b488dde 24/44: Merge branch 'dev', Stefan Monnier, 2021/03/27
- [elpa] externals/names 787c1f1 26/44: Merge branch 'dev', Stefan Monnier, 2021/03/27
- [elpa] externals/names d8baba5 43/44: Merge pull request #30 from jabranham/byte-compiler-warns, Stefan Monnier, 2021/03/27
- [elpa] externals/names 00862c5 38/44: Merge branch 'dev', Stefan Monnier, 2021/03/27
- [elpa] externals/names 1d45ec5 41/44: Merge branch 'elpa', Stefan Monnier, 2021/03/27
- [elpa] externals/names b269f61 44/44: Merge remote-tracking branch 'upstream/names/main' into externals/names, Stefan Monnier, 2021/03/27
- [elpa] externals/names 48ed6aa 03/44: Merge branch 'elpa' into dev, Stefan Monnier, 2021/03/27
- [elpa] externals/names e2c0bd9 13/44: Merge branch 'elpa' into dev, Stefan Monnier, 2021/03/27
- [elpa] externals/names 9ebceab 39/44: Add file tests/.nosearch, Stefan Monnier, 2021/03/27
- [elpa] externals/names 7cad62b 42/44: Silence the byte compiler, Stefan Monnier, 2021/03/27