emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[OT] Working with patches inlined in emails (was: Using gv in map and se


From: Nicolas Petton
Subject: [OT] Working with patches inlined in emails (was: Using gv in map and seq?)
Date: Thu, 18 Jun 2015 10:31:20 +0200
User-agent: Notmuch/0.19 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-redhat-linux-gnu)

Stefan Monnier <address@hidden> writes:

> diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el
> index dd7fb91..26ad6ce 100644
> --- a/lisp/emacs-lisp/map.el
> +++ b/lisp/emacs-lisp/map.el
> @@ -82,25 +82,19 @@ The following keyword types are meaningful: `:list',
>  
>  An error is thrown if MAP is neither a list, hash-table nor array.
>  
> -Return RESULT if non-nil or the result of evaluation of the
> -form.
> +Return RESULT if non-nil or the result of evaluation of the form.
>  
>  \(fn (VAR MAP [RESULT]) &rest ARGS)"
>    (declare (debug t) (indent 1))
>    (unless (listp spec)
>      (setq spec `(,spec ,spec)))
> -  (let ((map-var (car spec))
> -        (result-var (make-symbol "result")))
> -    `(let ((,map-var ,(cadr spec))
> -           ,result-var)
> -       (setq ,result-var
> -             (cond ((listp ,map-var) ,(plist-get args :list))
> -                   ((hash-table-p ,map-var) ,(plist-get args :hash-table))
> -                   ((arrayp ,map-var) ,(plist-get args :array))
> -                   (t (error "Unsupported map: %s" ,map-var))))
> -       ,@(when (cddr spec)
> -           `((setq ,result-var ,@(cddr spec))))
> -       ,result-var)))
> +  (let ((map-var (car spec)))
> +    `(let* ,(unless (eq map-var (cadr spec)) `((,map-var ,(cadr spec))))
> +       (cond ((listp ,map-var) ,(plist-get args :list))
> +             ((hash-table-p ,map-var) ,(plist-get args :hash-table))
> +             ((arrayp ,map-var) ,(plist-get args :array))
> +             (t (error "Unsupported map: %s" ,map-var)))
> +       ,@(cddr spec))))
>  
>  (defun map-elt (map key &optional default)
>    "Perform a lookup in MAP of KEY and return its associated value.
> @@ -109,27 +103,23 @@ If KEY is not found, return DEFAULT which defaults to 
> nil.
>  If MAP is a list, `equal' is used to lookup KEY.
>  
>  MAP can be a list, hash-table or array."
> +  (declare
> +   (gv-expander
> +    (lambda (do)
> +      (macroexp-let2* nil
> +          ;; Eval them once and for all in the right order.
> +          ((map map) (key key) (default default))
> +        `(map--dispatch map
> +           :list ,(gv-get `(alist-get ,key ,map ,default) do)
> +           :hash-table ,(funcall do `(gethash ,key ,map ,default)
> +                                 (lambda (v) `(puthash ,key ,v ,map)))
> +           :array ,(funcall do `(aref ,map ,key)
> +                            (lambda (v) `(aset ,map ,key ,v))))))))
>    (map--dispatch map
>      :list (map--elt-list map key default)
>      :hash-table (gethash key map default)
>      :array (map--elt-array map key default)))
>  
> -(defmacro map-put (map key value)
> -  "In MAP, associate KEY with VALUE and return MAP.
> -If KEY is already present in MAP, replace the associated value
> -with VALUE.
> -
> -MAP can be a list, hash-table or array."
> -  (declare (debug t))
> -  (let ((symbol (symbolp map)))
> -    `(progn
> -       (map--dispatch (m ,map m)
> -         :list (if ,symbol
> -                   (setq ,map (cons (cons ,key ,value) m))
> -                 (error "Literal lists are not allowed, %s must be a symbol" 
> ',map))
> -         :hash-table (puthash ,key ,value m)
> -         :array (aset m ,key ,value)))))
> -
>  (defmacro map-delete (map key)
>    "In MAP, delete the key KEY if present and return MAP.
>  If MAP is an array, store nil at the index KEY.


This is a bit off-topic, but I'm wondering how people work with emails
in Emacs containing patches in the body of the email.

With patches sent as attachments it's straightforward, but for example
here for this patch I had to yank the content in a new buffer, trim the
spaces at the beginning of each line, etc. which is clearly not
efficient (I use notmuch).

Cheers,
Nico
-- 
Nicolas Petton
http://nicolas-petton.fr

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]