From 61cec32dbe29fe1ce16b542942e0ccb7219621ed Mon Sep 17 00:00:00 2001 From: Antoine Brand Date: Tue, 30 Sep 2014 19:45:52 +0200 Subject: [PATCH 1/3] * Added a helm interface to all the things return by xref-index --- cmds.rkt | 1 + racket-mode.el | 26 ++++++++++++++++++++++++++ scribble.rkt | 18 ++++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/cmds.rkt b/cmds.rkt index f781f01a..d23358c7 100644 --- a/cmds.rkt +++ b/cmds.rkt @@ -40,6 +40,7 @@ [(uq cmd) (eq? 'unquote (syntax-e #'uq)) (case (syntax-e #'cmd) + [(apropos) (elisp-println (scribble-decl-list))] [(run) (run put/stop rerun)] [(top) (top put/stop rerun)] [(def) (def (read))] diff --git a/racket-mode.el b/racket-mode.el index 507d86c2..06466c24 100644 --- a/racket-mode.el +++ b/racket-mode.el @@ -144,6 +144,32 @@ http://www.gnu.org/licenses/ for details.") (set (make-local-variable 'imenu-syntax-alist) '(("+-*/.<>=?!$%_&~^:" . "w")))) +(require 'helm) + +(defun helm-racket-apropos-init () + (with-current-buffer (helm-candidate-buffer 'global) + (dolist (elem (racket--eval/sexpr ",apropos")) + (insert (car elem) "\n")))) + +(defun helm-racket-apropos-match-part (candidate) + candidate) + +(defun helm-racket-apropos-action (candidate) + (racket--do-describe candidate t)) + +(defvar helm-source-racket-apropos + '((name . "Search throught racket defining symbol") + (init . helm-racket-apropos-init) + (candidates-in-buffer) + (get-line . buffer-substring) + (match-part . helm-racket-apropos-match-part) + (action . helm-racket-apropos-action))) + +(defun helm-racket-apropos () + "Equivalent of helm-apropos but for the racket installed documentation" + (interactive) + (helm :sources 'helm-source-racket-apropos :buffer "*helm racket apropos*")) + ;;;###autoload (define-derived-mode racket-mode prog-mode "Racket" diff --git a/scribble.rkt b/scribble.rkt index c2c0eec5..e72c8c4b 100644 --- a/scribble.rkt +++ b/scribble.rkt @@ -1,13 +1,19 @@ #lang racket/base (require racket/file + racket/list racket/match scribble/xref setup/xref (only-in xml xml->xexpr element xexpr->string) (only-in html read-html-as-xml)) -(provide scribble-doc/html) +(provide scribble-doc/html + scribble-decl-list) + +(define (scribble-decl-list) + (define xref (fix-load-collections-xref)) + (map entry-words (xref-index xref))) (module+ test (require rackunit)) @@ -27,8 +33,16 @@ (define-values (path anchor) (binding->path+anchor stx)) (and path anchor (scribble-get-xexpr path anchor))) +(define fix-xref #f) + +(define (fix-load-collections-xref) + (when (not fix-xref) + (set! fix-xref (load-collections-xref)) + (void (xref-index fix-xref))) + fix-xref) + (define (binding->path+anchor stx) - (define xref (load-collections-xref)) + (define xref (fix-load-collections-xref)) (define tag (and (identifier? stx) (xref-binding->definition-tag xref stx 0))) (cond [tag (xref-tag->path+anchor xref tag)] From a8d93d743d7ecad29ed18f940812b75aace9e307 Mon Sep 17 00:00:00 2001 From: Antoine Brand Date: Wed, 1 Oct 2014 22:06:51 +0200 Subject: [PATCH 2/3] * Changed to make it not depend on helm, and use the racket- convention --- racket-mode.el | 51 +++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/racket-mode.el b/racket-mode.el index 06466c24..3dc021dc 100644 --- a/racket-mode.el +++ b/racket-mode.el @@ -144,31 +144,32 @@ http://www.gnu.org/licenses/ for details.") (set (make-local-variable 'imenu-syntax-alist) '(("+-*/.<>=?!$%_&~^:" . "w")))) -(require 'helm) - -(defun helm-racket-apropos-init () - (with-current-buffer (helm-candidate-buffer 'global) - (dolist (elem (racket--eval/sexpr ",apropos")) - (insert (car elem) "\n")))) - -(defun helm-racket-apropos-match-part (candidate) - candidate) - -(defun helm-racket-apropos-action (candidate) - (racket--do-describe candidate t)) - -(defvar helm-source-racket-apropos - '((name . "Search throught racket defining symbol") - (init . helm-racket-apropos-init) - (candidates-in-buffer) - (get-line . buffer-substring) - (match-part . helm-racket-apropos-match-part) - (action . helm-racket-apropos-action))) - -(defun helm-racket-apropos () - "Equivalent of helm-apropos but for the racket installed documentation" - (interactive) - (helm :sources 'helm-source-racket-apropos :buffer "*helm racket apropos*")) +(when (fboundp 'helm) + (require 'helm) + + (defun racket-helm-apropos-init () + (with-current-buffer (helm-candidate-buffer 'global) + (dolist (elem (racket--eval/sexpr ",apropos")) + (insert (car elem) "\n")))) + + (defun racket-helm-apropos-match-part (candidate) + candidate) + + (defun racket-helm-apropos-action (candidate) + (racket--do-describe candidate t)) + + (defvar helm-source-racket-apropos + '((name . "Search throught racket defining symbol") + (init . racket-helm-apropos-init) + (candidates-in-buffer) + (get-line . buffer-substring) + (match-part . racket-helm-apropos-match-part) + (action . racket-helm-apropos-action))) + + (defun racket-helm-apropos () + "Equivalent of helm-apropos but for the racket installed documentation" + (interactive) + (helm :sources 'helm-source-racket-apropos :buffer "*helm racket apropos*"))) ;;;###autoload (define-derived-mode racket-mode prog-mode From 4318ea92f61d4155ed8f96fa64524f561f5dbbf3 Mon Sep 17 00:00:00 2001 From: Antoine Brand Date: Wed, 1 Oct 2014 22:56:50 +0200 Subject: [PATCH 3/3] * Now it is byte compilable --- racket-mode.el | 22 ++++++++++++---------- scribble.rkt | 16 ++++------------ 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/racket-mode.el b/racket-mode.el index 3dc021dc..35f60553 100644 --- a/racket-mode.el +++ b/racket-mode.el @@ -144,13 +144,14 @@ http://www.gnu.org/licenses/ for details.") (set (make-local-variable 'imenu-syntax-alist) '(("+-*/.<>=?!$%_&~^:" . "w")))) -(when (fboundp 'helm) - (require 'helm) - (defun racket-helm-apropos-init () - (with-current-buffer (helm-candidate-buffer 'global) - (dolist (elem (racket--eval/sexpr ",apropos")) - (insert (car elem) "\n")))) +(when (require 'helm nil 't) + + (when (fboundp 'helm-candidate-buffer) + (defun racket-helm-apropos-init () + (with-current-buffer (helm-candidate-buffer 'global) + (dolist (elem (racket--eval/sexpr ",apropos")) + (insert (car elem) "\n"))))) (defun racket-helm-apropos-match-part (candidate) candidate) @@ -166,10 +167,11 @@ http://www.gnu.org/licenses/ for details.") (match-part . racket-helm-apropos-match-part) (action . racket-helm-apropos-action))) - (defun racket-helm-apropos () - "Equivalent of helm-apropos but for the racket installed documentation" - (interactive) - (helm :sources 'helm-source-racket-apropos :buffer "*helm racket apropos*"))) + (when (fboundp 'helm) + (defun racket-helm-apropos () + "Equivalent of helm-apropos but for the racket installed documentation" + (interactive) + (helm :sources 'helm-source-racket-apropos :buffer "*helm racket apropos*")))) ;;;###autoload (define-derived-mode racket-mode prog-mode diff --git a/scribble.rkt b/scribble.rkt index e72c8c4b..8681e98d 100644 --- a/scribble.rkt +++ b/scribble.rkt @@ -1,7 +1,7 @@ #lang racket/base (require racket/file - racket/list + racket/list racket/match scribble/xref setup/xref @@ -9,10 +9,10 @@ (only-in html read-html-as-xml)) (provide scribble-doc/html - scribble-decl-list) + scribble-decl-list) (define (scribble-decl-list) - (define xref (fix-load-collections-xref)) + (define xref (load-collections-xref)) (map entry-words (xref-index xref))) (module+ test @@ -33,16 +33,8 @@ (define-values (path anchor) (binding->path+anchor stx)) (and path anchor (scribble-get-xexpr path anchor))) -(define fix-xref #f) - -(define (fix-load-collections-xref) - (when (not fix-xref) - (set! fix-xref (load-collections-xref)) - (void (xref-index fix-xref))) - fix-xref) - (define (binding->path+anchor stx) - (define xref (fix-load-collections-xref)) + (define xref (load-collections-xref)) (define tag (and (identifier? stx) (xref-binding->definition-tag xref stx 0))) (cond [tag (xref-tag->path+anchor xref tag)]