;;; cider-util.el --- Common utility functions that don't belong anywhere else ;; Copyright © 2012-2013 Tim King, Phil Hagelberg ;; Copyright © 2013 Bozhidar Batsov, Hugo Duncan, Steve Purcell ;; ;; Author: Tim King ;; Phil Hagelberg ;; Bozhidar Batsov ;; Hugo Duncan ;; Steve Purcell ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;; This file is not part of GNU Emacs. ;;; Commentary: ;; Common utility functions that don't belong anywhere else ;;; Code: (require 'dash) ;;; Compatibility (eval-and-compile ;; `setq-local' for Emacs 24.2 and below (unless (fboundp 'defvar-local) (defmacro defvar-local (var val &optional docstring) "Define VAR as a buffer-local variable with default value VAL. Like `defvar' but additionally marks the variable as being automatically buffer-local wherever it is set." (declare (debug defvar) (doc-string 3)) `(progn (defvar ,var ,val ,docstring) (make-variable-buffer-local ',var)))) ;; `setq-local' for Emacs 24.2 and below (unless (fboundp 'setq-local) (defmacro setq-local (var val) "Set variable VAR to value VAL in current buffer." `(set (make-local-variable ',var) ,val)))) (defun cider-util--hash-keys (hashtable) "Return a list of keys in HASHTABLE." (let ((keys '())) (maphash (lambda (k v) (setq keys (cons k keys))) hashtable) keys)) (defun cider-util--clojure-buffers () "Return a list of all existing `clojure-mode' buffers." (-filter (lambda (buffer) (with-current-buffer buffer (derived-mode-p 'clojure-mode))) (buffer-list))) (defun cider-font-lock-as-clojure (string) "Font-lock STRING as Clojure code." (with-temp-buffer (insert string) (clojure-mode) (font-lock-fontify-buffer) (buffer-string))) (provide 'cider-util) ;;; cider-util.el ends here