Personal emacs config
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.6 KiB

  1. ;;; le-julia.el --- lispy support for Julia. -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2016 Oleh Krehel
  3. ;; This file is not part of GNU Emacs
  4. ;; This file is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation; either version 3, or (at your option)
  7. ;; any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; For a full copy of the GNU General Public License
  13. ;; see <http://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;;
  16. ;;; Code:
  17. (require 'julia-mode nil t)
  18. (require 'julia-shell nil t)
  19. (declare-function julia-shell-collect-command-output "ext:julia-shell")
  20. (defun lispy--eval-julia (str &optional _plain)
  21. "Eval STR as Julia code."
  22. (string-trim-right (julia-shell-collect-command-output str)))
  23. ;; TODO: simplify
  24. (defun lispy-eval-julia (&optional _plain)
  25. (let (str bnd res)
  26. (setq str
  27. (save-excursion
  28. (cond ((region-active-p)
  29. ;; get rid of "unexpected indent"
  30. (replace-regexp-in-string
  31. (concat
  32. "^"
  33. (save-excursion
  34. (goto-char (region-beginning))
  35. (buffer-substring-no-properties
  36. (line-beginning-position)
  37. (point))))
  38. "" (lispy--string-dwim)))
  39. ((looking-at lispy-outline)
  40. (string-trim-right
  41. (lispy--string-dwim
  42. (lispy--bounds-dwim))))
  43. ((lispy-bolp)
  44. (lispy--string-dwim
  45. (lispy--bounds-c-toplevel)))
  46. (t
  47. (cond ((lispy-left-p))
  48. ((lispy-right-p)
  49. (backward-list))
  50. (t
  51. (error "Unexpected")))
  52. (setq bnd (lispy--bounds-dwim))
  53. (ignore-errors (backward-sexp))
  54. (while (eq (char-before) ?.)
  55. (backward-sexp))
  56. (setcar bnd (point))
  57. (lispy--string-dwim bnd)))))
  58. (setq res (lispy--eval-julia str))
  59. (if res
  60. (lispy-message
  61. (replace-regexp-in-string
  62. "%" "%%" res))
  63. (lispy-message lispy-eval-error))))
  64. (provide 'le-julia)
  65. ;;; le-julia.el ends here