Klimi's new dotfiles with stow.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

110 linhas
3.5 KiB

5 anos atrás
  1. ;;; cider-classpath.el --- Basic Java classpath browser
  2. ;; Copyright © 2014-2019 Bozhidar Batsov and CIDER contributors
  3. ;; This program is free software: you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;; This file is not part of GNU Emacs.
  14. ;;; Commentary:
  15. ;; Basic Java classpath browser for CIDER.
  16. ;;; Code:
  17. (require 'cider-client)
  18. (require 'cider-popup)
  19. (require 'subr-x)
  20. (require 'cider-compat)
  21. (defvar cider-classpath-buffer "*cider-classpath*")
  22. (defvar cider-classpath-mode-map
  23. (let ((map (make-sparse-keymap)))
  24. (set-keymap-parent map cider-popup-buffer-mode-map)
  25. (define-key map (kbd "RET") #'cider-classpath-operate-on-point)
  26. (define-key map "n" #'next-line)
  27. (define-key map "p" #'previous-line)
  28. map))
  29. (defvar cider-classpath-mouse-map
  30. (let ((map (make-sparse-keymap)))
  31. (define-key map [mouse-1] #'cider-classpath-handle-mouse)
  32. map))
  33. (define-derived-mode cider-classpath-mode special-mode "classpath"
  34. "Major mode for browsing the entries in Java's classpath.
  35. \\{cider-classpath-mode-map}"
  36. (setq-local electric-indent-chars nil)
  37. (setq-local sesman-system 'CIDER)
  38. (when cider-special-mode-truncate-lines
  39. (setq-local truncate-lines t)))
  40. (defun cider-classpath-list (buffer items)
  41. "Populate BUFFER with ITEMS."
  42. (with-current-buffer buffer
  43. (cider-classpath-mode)
  44. (let ((inhibit-read-only t))
  45. (erase-buffer)
  46. (dolist (item items)
  47. (insert item "\n"))
  48. (goto-char (point-min)))))
  49. (defun cider-classpath-properties (text)
  50. "Decorate TEXT with a clickable keymap and function face."
  51. (let ((face (cond
  52. ((not (file-exists-p text)) 'font-lock-warning-face)
  53. ((file-directory-p text) 'dired-directory)
  54. (t 'default))))
  55. (propertize text
  56. 'font-lock-face face
  57. 'mouse-face 'highlight
  58. 'keymap cider-classpath-mouse-map)))
  59. (defun cider-classpath-operate-on-point ()
  60. "Expand browser according to thing at current point."
  61. (interactive)
  62. (let* ((bol (line-beginning-position))
  63. (eol (line-end-position))
  64. (line (buffer-substring-no-properties bol eol)))
  65. (find-file-other-window line)))
  66. (defun cider-classpath-handle-mouse (event)
  67. "Handle mouse click EVENT."
  68. (interactive "e")
  69. (cider-classpath-operate-on-point))
  70. ;;;###autoload
  71. (defun cider-classpath ()
  72. "List all classpath entries."
  73. (interactive)
  74. (cider-ensure-connected)
  75. (with-current-buffer (cider-popup-buffer cider-classpath-buffer 'select nil 'ancillary)
  76. (cider-classpath-list (current-buffer)
  77. (mapcar (lambda (name)
  78. (cider-classpath-properties name))
  79. (cider-classpath-entries)))))
  80. ;;;###autoload
  81. (defun cider-open-classpath-entry ()
  82. "Open a classpath entry."
  83. (interactive)
  84. (cider-ensure-connected)
  85. (when-let* ((entry (completing-read "Classpath entries: " (cider-classpath-entries))))
  86. (find-file-other-window entry)))
  87. (provide 'cider-classpath)
  88. ;;; cider-classpath.el ends here