all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* mutate list by appending a list (and similar for props)
@ 2014-09-08 18:42 Sam Halliday
  2014-09-08 19:29 ` Barry Margolin
  0 siblings, 1 reply; 8+ messages in thread
From: Sam Halliday @ 2014-09-08 18:42 UTC (permalink / raw
  To: help-gnu-emacs

Hi all,

I often find that I am repeating calls to add-to-list (mutates) / plist-put (immutable) in my .emacs [1] configuration against the same variable. I'd like to be able to pass a list of elements to be appended/prepended to the variable to save on boilerplate.

It would be trivial to write a little function that repeats the operation for a list input, but I'd rather use something that is already in the emacs distro (or at least in a very lightweight MELPA package).

Does such a thing exist?


[1] https://github.com/fommil/unix/blob/master/.emacs

Best regards,
Sam


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: mutate list by appending a list (and similar for props)
  2014-09-08 18:42 mutate list by appending a list (and similar for props) Sam Halliday
@ 2014-09-08 19:29 ` Barry Margolin
  2014-09-18  9:37   ` Sam Halliday
  0 siblings, 1 reply; 8+ messages in thread
From: Barry Margolin @ 2014-09-08 19:29 UTC (permalink / raw
  To: help-gnu-emacs

In article <3710b1bf-1e23-4147-b6ea-40c360fb16b4@googlegroups.com>,
 Sam Halliday <sam.halliday@gmail.com> wrote:

> Hi all,
> 
> I often find that I am repeating calls to add-to-list (mutates) / plist-put 
> (immutable) in my .emacs [1] configuration against the same variable. I'd 
> like to be able to pass a list of elements to be appended/prepended to the 
> variable to save on boilerplate.
> 
> It would be trivial to write a little function that repeats the operation for 
> a list input, but I'd rather use something that is already in the emacs 
> distro (or at least in a very lightweight MELPA package).
> 
> Does such a thing exist?

The append function does it:

(setq list (append additional-list list))

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: mutate list by appending a list (and similar for props)
  2014-09-08 19:29 ` Barry Margolin
@ 2014-09-18  9:37   ` Sam Halliday
  2014-09-18  9:42     ` Sam Halliday
                       ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Sam Halliday @ 2014-09-18  9:37 UTC (permalink / raw
  To: help-gnu-emacs

On Monday, 8 September 2014 20:29:17 UTC+1, Barry Margolin  wrote:
>  Sam Halliday <sam.halliday@gmail.com> wrote:
> > I often find that I am repeating calls to add-to-list (mutates) / plist-put 
> > (immutable) in my .emacs [1] configuration against the same variable. I'd 
> > like to be able to pass a list of elements to be appended/prepended to the 
> > variable to save on boilerplate.
> 
> > It would be trivial to write a little function that repeats the operation for 
> > a list input, but I'd rather use something that is already in the emacs 
> > distro (or at least in a very lightweight MELPA package).
> 
> > Does such a thing exist?
> 
> 
> 
> The append function does it:
> 
> (setq list (append additional-list list))


Thanks! But that's not ideal because it involves repeating the list symbol (which can often be quite long).


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: mutate list by appending a list (and similar for props)
  2014-09-18  9:37   ` Sam Halliday
@ 2014-09-18  9:42     ` Sam Halliday
  2014-09-18  9:44       ` Sam Halliday
  2014-09-18 10:10     ` Michael Heerdegen
       [not found]     ` <mailman.9095.1411035073.1147.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 8+ messages in thread
From: Sam Halliday @ 2014-09-18  9:42 UTC (permalink / raw
  To: help-gnu-emacs

On Thursday, 18 September 2014 10:37:52 UTC+1, Sam Halliday  wrote:
> On Monday, 8 September 2014 20:29:17 UTC+1, Barry Margolin  wrote:
> 
> >  Sam Halliday <sam.halliday@gmail.com> wrote:
> 
> > > I often find that I am repeating calls to add-to-list (mutates) / plist-put 
> 
> > > (immutable) in my .emacs [1] configuration against the same variable. I'd 
> 
> > > like to be able to pass a list of elements to be appended/prepended to the 
> 
> > > variable to save on boilerplate.
> 
> > 
> 
> > > It would be trivial to write a little function that repeats the operation for 
> 
> > > a list input, but I'd rather use something that is already in the emacs 
> 
> > > distro (or at least in a very lightweight MELPA package).
> 
> > 
> 
> > > Does such a thing exist?
> 
> > 
> 
> > 
> 
> > 
> 
> > The append function does it:
> 
> > 
> 
> > (setq list (append additional-list list))
> 
> 
> 
> 
> 
> Thanks! But that's not ideal because it involves repeating the list symbol (which can often be quite long).

(It also doesn't work when the original list is nil)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: mutate list by appending a list (and similar for props)
  2014-09-18  9:42     ` Sam Halliday
@ 2014-09-18  9:44       ` Sam Halliday
  0 siblings, 0 replies; 8+ messages in thread
From: Sam Halliday @ 2014-09-18  9:44 UTC (permalink / raw
  To: help-gnu-emacs

On Thursday, 18 September 2014 10:42:03 UTC+1, Sam Halliday  wrote:
> (It also doesn't work when the original list is nil)

Ignore this comment: I was getting an error from another line.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: mutate list by appending a list (and similar for props)
  2014-09-18  9:37   ` Sam Halliday
  2014-09-18  9:42     ` Sam Halliday
@ 2014-09-18 10:10     ` Michael Heerdegen
       [not found]     ` <mailman.9095.1411035073.1147.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 8+ messages in thread
From: Michael Heerdegen @ 2014-09-18 10:10 UTC (permalink / raw
  To: help-gnu-emacs

Sam Halliday <sam.halliday@gmail.com> writes:

> > (setq list (append additional-list list))
>
> Thanks! But that's not ideal because it involves repeating the list
> symbol (which can often be quite long).

Try (cl-callf2 append additional-list list) instead, which expands
exactly into the above expression.

Michael.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: mutate list by appending a list (and similar for props)
       [not found]     ` <mailman.9095.1411035073.1147.help-gnu-emacs@gnu.org>
@ 2014-09-18 16:53       ` Pascal J. Bourguignon
  2014-09-18 23:44         ` Stefan Monnier
  0 siblings, 1 reply; 8+ messages in thread
From: Pascal J. Bourguignon @ 2014-09-18 16:53 UTC (permalink / raw
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Sam Halliday <sam.halliday@gmail.com> writes:
>
>> > (setq list (append additional-list list))
>>
>> Thanks! But that's not ideal because it involves repeating the list
>> symbol (which can often be quite long).
>
> Try (cl-callf2 append additional-list list) instead, which expands
> exactly into the above expression.

No!


You want prependf:


(require 'cl) ; of course!

(define-modify-macro appendf (&rest args) append "Append onto list")

(let ((list '(1 2 3)))
  (appendf list '(4 5 6) '(7 8 9))
  list)
--> (1 2 3 4 5 6 7 8 9)



(defun prepend (dest-list &rest other-lists)
  (apply (function append) (append other-lists (list dest-list))))
(define-modify-macro prependf (&rest args) prepend "Prepend to list")

(let ((list '(1 2 3)))
  (prependf list '(4 5 6) '(7 8 9))
  list)
--> (4 5 6 7 8 9 1 2 3)


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: mutate list by appending a list (and similar for props)
  2014-09-18 16:53       ` Pascal J. Bourguignon
@ 2014-09-18 23:44         ` Stefan Monnier
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2014-09-18 23:44 UTC (permalink / raw
  To: help-gnu-emacs

> (define-modify-macro appendf (&rest args) append "Append onto list")

With GV, this would be

   (defmacro sm-appendf (place &rest args)
     (gv-letplace (getter setter) place
       (funcall setter `(append ,getter ,@args))))

> (defun prepend (dest-list &rest other-lists)
>   (apply (function append) (append other-lists (list dest-list))))
> (define-modify-macro prependf (&rest args) prepend "Prepend to list")

Which with GV would turn into

   (defmacro sm-appendf (place &rest args)
     (gv-letplace (getter setter) place
       (funcall setter `(append ,@args ,getter))))


-- Stefan




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-09-18 23:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-08 18:42 mutate list by appending a list (and similar for props) Sam Halliday
2014-09-08 19:29 ` Barry Margolin
2014-09-18  9:37   ` Sam Halliday
2014-09-18  9:42     ` Sam Halliday
2014-09-18  9:44       ` Sam Halliday
2014-09-18 10:10     ` Michael Heerdegen
     [not found]     ` <mailman.9095.1411035073.1147.help-gnu-emacs@gnu.org>
2014-09-18 16:53       ` Pascal J. Bourguignon
2014-09-18 23:44         ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.