2015-01-27 03:51:47 +00:00
|
|
|
;;; core-funcs.el --- Spacemacs Core File
|
2015-01-27 03:39:14 +00:00
|
|
|
;;
|
|
|
|
;; Copyright (c) 2012-2014 Sylvain Benner
|
|
|
|
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
|
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
(defun spacemacs/mplist-get (plist prop)
|
|
|
|
"Get the values associated to PROP in PLIST, a modified plist.
|
|
|
|
|
|
|
|
A modified plist is one where keys are keywords and values are
|
|
|
|
all non-keywords elements that follow it.
|
|
|
|
|
|
|
|
If there are multiple properties with the same keyword, only the first property
|
|
|
|
and its values is returned.
|
|
|
|
|
|
|
|
Currently this function infloops when the list is circular."
|
|
|
|
(let ((tail plist)
|
|
|
|
result)
|
|
|
|
(while (and (consp tail) (not (eq prop (car tail))))
|
|
|
|
(pop tail))
|
|
|
|
;; pop the found keyword
|
|
|
|
(pop tail)
|
|
|
|
(while (and (consp tail) (not (keywordp (car tail))))
|
|
|
|
(push (pop tail) result))
|
|
|
|
(nreverse result)))
|
|
|
|
|
|
|
|
(defun spacemacs/mplist-remove (plist prop)
|
|
|
|
"Return a copy of a modified PLIST without PROP and its values.
|
|
|
|
|
|
|
|
If there are multiple properties with the same keyword, only the first property
|
|
|
|
and its values are removed."
|
|
|
|
(let ((tail plist)
|
|
|
|
result)
|
|
|
|
(while (and (consp tail) (not (eq prop (car tail))))
|
|
|
|
(push (pop tail) result))
|
|
|
|
(when (eq prop (car tail))
|
|
|
|
(pop tail)
|
|
|
|
(while (and (consp tail) (not (keywordp (car tail))))
|
|
|
|
(pop tail)))
|
|
|
|
(while (consp tail)
|
|
|
|
(push (pop tail) result))
|
|
|
|
(nreverse result)))
|
|
|
|
|
2015-02-04 04:56:38 +00:00
|
|
|
;; From http://stackoverflow.com/questions/2321904/elisp-how-to-save-data-in-a-file
|
|
|
|
(defun spacemacs/dump-vars-to-file (varlist filename)
|
|
|
|
"simplistic dumping of variables in VARLIST to a file FILENAME"
|
|
|
|
(save-excursion
|
|
|
|
(let ((buf (find-file-noselect filename)))
|
|
|
|
(set-buffer buf)
|
|
|
|
(erase-buffer)
|
|
|
|
(spacemacs/dump varlist buf)
|
|
|
|
(make-directory (file-name-directory filename) t)
|
|
|
|
(save-buffer)
|
|
|
|
(kill-buffer))))
|
|
|
|
|
|
|
|
;; From http://stackoverflow.com/questions/2321904/elisp-how-to-save-data-in-a-file
|
|
|
|
(defun spacemacs/dump (varlist buffer)
|
|
|
|
"insert into buffer the setq statement to recreate the variables in VARLIST"
|
|
|
|
(loop for var in varlist do
|
|
|
|
(print (list 'setq var (list 'quote (symbol-value var)))
|
|
|
|
buffer)))
|
|
|
|
|
2015-01-27 03:51:47 +00:00
|
|
|
(provide 'core-funcs)
|