From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas S. Dye Subject: Re: how the $@%& do you add a property to a plist? Date: Sat, 18 Jul 2015 10:01:27 -1000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44812) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZGYIu-0001tC-68 for emacs-orgmode@gnu.org; Sat, 18 Jul 2015 16:01:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZGYIq-0007pv-Nn for emacs-orgmode@gnu.org; Sat, 18 Jul 2015 16:01:48 -0400 Received: from gproxy6-pub.mail.unifiedlayer.com ([67.222.39.168]:51306) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1ZGYIq-0007oh-HG for emacs-orgmode@gnu.org; Sat, 18 Jul 2015 16:01:44 -0400 In-reply-to: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Matt Price Cc: Org Mode Matt Price writes: > Hi, > > I am continuing to work on my marking stuff; it's working really well, > actually. > > I am currently importing a list of student names and emails from a csv file > -- this is normally how I get the list of enrolled students. I have > modified the defauly settings from our Universities CSV export so I get > these files in the form: > > Student Name,Email > Student One, em.address@utoronto.ca > Student Two, em.address2@utoronto.ca > > I then parse this into a list, each element of which is itself a list > ("Student One" "em.address@utoronto.ca"), etc. > > This is OK, but not very robust. I would like instead to set *properties*, > in case the CSV file has some other ordering of fields. So I've tried this: > > (defun parse-plist-csv-file (file) > (interactive > (list (read-file-name "CSV file: "))) > (let ((buf (find-file-noselect file)) > (result nil)) > (with-current-buffer buf > (goto-char (point-min)) > (let ((header (split-string (buffer-substring-no-properties > (line-beginning-position) > (line-end-position)) ",")) > ) > (while (not (eobp)) > (let ((line (split-string (buffer-substring-no-properties > (line-beginning-position) > (line-end-position)))) > (count 0) > (new-plist '())) > (while (< count (length line)) > (setq plist-new (plist-put new-plist '(nth count header) > (nth count line))) > (setq count (1+ count))) > (push new-plist result) > (forward-line 1)))) > (reverse result)))) > > The line that's not working here is: > > (setq plist-new (plist-put new-plist '(nth count header) > (nth count line))) > > which just inserts nil nil into 'new-plist. Obviously I'm making some > elementary elsip mistake, but my elisp is too weak to figure it out. Can > you guys help? thanks, > Matt According to plist-put's documentation: (setq x (plist-put x prop val)) (setq new-plist (plist-put new-plist (nth count header) (nth count line))) ^^^^^^^^^ ^ So, you don't want plist-new, I think. Also, quoting the first (nth ...) list means the function nth is interpreted as a value of the list, rather than a function. I think you want it to return a property. I didn't test any of this, so your mmv. hth, Tom -- Thomas S. Dye http://www.tsdye.com