From: Ian Kelling Date: Mon, 7 Jul 2014 09:40:05 +0000 (-0700) Subject: Fix minor bugs, mostly for linkedin X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=e66aaf94ff2b84e084256e58f38ec7887b81e43f;p=bbdb-csv-import Fix minor bugs, mostly for linkedin Thanks to Gijs Hillenius for reporting these bugs Linkedin began appending ^M chars at the end of lines, remove them Linkedin began having trailing blank lines, remove them pcsv brings along text properties when parsing a buffer, which end up as spam in the bbdb file. Functionally does not seem to be a problem, but the bbdb file is human readable, and this makes it far less so. I don't know how to strip the text properties from all the strings. We could use a temp buffer and file, but I expect csv buffers will always have underlying files, and it's good for them to anyways to diagnose any problems, so always save and read from the underlying csv file. --- diff --git a/bbdb-csv-import.el b/bbdb-csv-import.el index 28c4fee..a5c2b59 100644 --- a/bbdb-csv-import.el +++ b/bbdb-csv-import.el @@ -110,10 +110,6 @@ ;; it ever did I would start a mailman or discourse to act as a mailing list ;; and forum. -;;; known bugs: -;; * linkedin data contains ^M characters that need to be removed before import -;; * blank lines are not ignored - ;;; Code: (require 'pcsv) @@ -369,19 +365,30 @@ don't want flattened." ;;;###autoload (defun bbdb-csv-import-file (filename) - "Parse and import csv file FILENAME to bbdb." + "Parse and import csv file FILENAME to bbdb. +The file will be saved to disk with blank lines and aberrant characters removed." (interactive "fCSV file containg contact data: ") (bbdb-csv-import-buffer (find-file-noselect filename))) ;;;###autoload (defun bbdb-csv-import-buffer (&optional buffer-or-name) - "Parse and import csv BUFFER-OR-NAME to bbdb. -Argument is a buffer or name of a buffer. -Defaults to current buffer." + "Parse and import csv buffer to bbdb. Interactively, it prompts for a buffer. +The buffer will be saved to disk with blank lines and aberrant characters removed. +BUFFER-OR-NAME is a buffer or name of a buffer, or the current buffer if nil." (interactive "bBuffer containing CSV contact data: ") (when (null bbdb-csv-import-mapping-table) (error "error: `bbdb-csv-import-mapping-table' is nil. Please set it and rerun.")) - (let* ((csv-data (pcsv-parse-buffer (get-buffer (or buffer-or-name (current-buffer))))) + (let* ((csv-buffer (get-buffer (or buffer-or-name (current-buffer)))) + (csv-data (save-excursion + (set-buffer csv-buffer) + ;; deal with blank lines and ^M from linkedin + (flush-lines "^\\s-*$") + (goto-char (point-min)) + ;; remove ^M aka ret characters + (while (re-search-forward (char-to-string 13) nil t) + (replace-match "")) + (basic-save-buffer) + (pcsv-parse-file buffer-file-name))) (csv-fields (car csv-data)) (csv-data (cdr csv-data)) (allow-dupes bbdb-allow-duplicates)