;;; Syntax highlighting for CLISP FFI forms
;;; Load this file from ~/.emacs or ~/.emacs.el

(font-lock-add-keywords
 'lisp-mode
 `((,(concat "(\\(def-\\(?:\\(call-\\(?:in\\|out\\)\\)\\|\\(c-const\\|c-var\\)"
             "\\|\\(c-enum\\|c-struct\\|c-type\\)\\)\\)\\>"
             "[ \t\n'\(]+\\(" lisp-mode-symbol-regexp "\\)")
    (1 'font-lock-keyword-face)
    (5 (cond ((match-beginning 2) 'font-lock-function-name-face)
             ((match-beginning 3) 'font-lock-variable-name-face)
             ((match-beginning 4) 'font-lock-type-face)
             (t 'error))))))

;; convert between lisp-style-symbols and ICantReadThis

(defun cantread-to-lisp-1 (name)
  "Convert ICantReadThis to i-cant-read-this"
  (let ((case-fold-search nil))
    (while (string-match "\\([a-z]\\)\\([A-Z]\\)" name)
      (setq name (replace-match "\\1-\\2" t nil name))))
  (downcase name))
(defun cantread-to-lisp (&optional point)
  "Convert the symbol-at-point from ICantReadThis to i-cant-read-this"
  (interactive "d")
  (goto-char point)
  (let* ((bounds (bounds-of-thing-at-point 'symbol))
         (name (buffer-substring-no-properties (car bounds) (cdr bounds))))
    (delete-region (car bounds) (cdr bounds))
    (insert (cantread-to-lisp-1 name))))

(defun lisp-to-cantread-1 (name)
  "Convert i-cant-read-this to ICantReadThis"
  (delete ?\- (capitalize name)))
(defun lisp-to-cantread (&optional point)
  "Convert the symbol-at-point from i-cant-read-this to ICantReadThis"
  (interactive "d")
  (goto-char point)
  (let* ((bounds (bounds-of-thing-at-point 'symbol))
         (name (buffer-substring-no-properties (car bounds) (cdr bounds))))
    (delete-region (car bounds) (cdr bounds))
    (insert (lisp-to-cantread-1 name))))
