emacs.d / dss-elisp-funcs.el

(defun dss/local-shell-command-to-string (str)
  "An alternative to shell-command-to-string that is always local
  so tramp doesn't get in the way"
    (call-process-shell-command str nil t)

(defun dss/file-to-string (file)
  "There must be a built-in that does this... why can't I find it?"
  (when (file-readable-p file)
      (insert-file-contents file)

(defun dss/map-define-key (mode-map keylist fname)
  "Like define-key but the key arg is a list that should be mapped over"
  (mapc (lambda (k)
            (define-key mode-map k fname)))

(defun dss/call-command-with-input (command input-str out-buffer &rest args)
  "A convenient wrapper around `call-process-region` that accepts a
  string input instead of a buffer region"
  (let ((args (or args "")))
      (insert input-str)
       (point-min) (point-max) command nil out-buffer nil args))))

(defun dss/async-call-command (command input &rest args)
  "An asynchronous version of `dss/call-command-with-input`"
  (apply 'dss/call-command-with-input (append (list command input 0) args)))

(defun partition-list (list length)
     while list
     collect (subseq list 0 length)
     do (setf list (nthcdr length list))))

(defun partition-vector (vector length)
     for i = 0 then (+ i length)
     while (< i (length vector))
     collect (subseq vector i (+ i length))))

(defun partition (sequence length)
   (etypecase sequence
      (list   (partition-list sequence length))
      (string (partition-vector sequence length)) ; emacs lisp strings are not vectors!
      (vector (partition-vector sequence length))))

(provide 'dss-elisp-funcs)