From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Kost Subject: [PATCH 4/7] emacs: Add 'guix-devel-use-current-module'. Date: Sat, 25 Jul 2015 11:49:54 +0300 Message-ID: <1437814197-6321-5-git-send-email-alezost@gmail.com> References: <1437814197-6321-1-git-send-email-alezost@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53414) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIvAB-0004S3-0Q for guix-devel@gnu.org; Sat, 25 Jul 2015 04:50:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZIvA9-00051w-Li for guix-devel@gnu.org; Sat, 25 Jul 2015 04:50:34 -0400 Received: from mail-la0-x234.google.com ([2a00:1450:4010:c03::234]:35185) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIvA9-00051A-7r for guix-devel@gnu.org; Sat, 25 Jul 2015 04:50:33 -0400 Received: by lahh5 with SMTP id h5so25654617lah.2 for ; Sat, 25 Jul 2015 01:50:32 -0700 (PDT) In-Reply-To: <1437814197-6321-1-git-send-email-alezost@gmail.com> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org Cc: Alex Kost * emacs/guix-guile.el (guix-guile-current-module): New function. * emacs/guix-devel.el: New file. (guix-devel-use-modules, guix-devel-use-current-module): New functions. * doc/emacs.texi (Emacs Development): New node. Document 'guix-devel-use-current-module'. --- doc/emacs.texi | 29 ++++++++++++++++++++++++++++- emacs/guix-devel.el | 44 ++++++++++++++++++++++++++++++++++++++++++++ emacs/guix-guile.el | 13 +++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 emacs/guix-devel.el diff --git a/doc/emacs.texi b/doc/emacs.texi index 180037a..6920bef 100644 --- a/doc/emacs.texi +++ b/doc/emacs.texi @@ -19,7 +19,8 @@ guix package}). Specifically, ``guix.el'' makes it easy to: * Usage: Emacs Usage. Using the interface. * Configuration: Emacs Configuration. Configuring the interface. * Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names. -* Completions: Emacs Completions. Completing @command{guix} shell command. +* Completions: Emacs Completions. Completing @command{guix} shell command. +* Development: Emacs Development. Tools for Guix developers. @end menu @node Emacs Initial Setup @@ -554,3 +555,29 @@ something: @item @code{guix lint --checkers=synopsis,des}@key{TAB} @end itemize + + +@node Emacs Development +@subsection Development + +This section describes some additional commands for Guix developers who +use Geiser to work with guile code. + +@table @kbd + +@item M-x guix-devel-use-current-module +Use the current guile module. Often after opening a scheme file, you +want to use a module it defines, so you switch to the Geiser REPL and +write @code{,use (some module)} there. You may just use this command +instead. + +@end table + +And as always if you use a command often, it is a good idea to bind a +key to it, for example like this: + +@example +(with-eval-after-load 'scheme + (define-key scheme-mode-map (kbd "C-c u") + 'guix-devel-use-current-module)) +@end example diff --git a/emacs/guix-devel.el b/emacs/guix-devel.el new file mode 100644 index 0000000..e99b289 --- /dev/null +++ b/emacs/guix-devel.el @@ -0,0 +1,44 @@ +;;; guix-devel.el --- Development tools + +;; Copyright © 2015 Alex Kost + +;; This file is part of GNU Guix. + +;; GNU Guix 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. + +;; GNU Guix 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 . + +;;; Commentary: + +;; This file provides commands useful for developing Guix (or even arbitrary +;; guile code) with Geiser. + +;;; Code: + +(require 'guix-guile) +(require 'guix-geiser) + +(defun guix-devel-use-modules (&rest modules) + "Use guile MODULES." + (apply #'guix-geiser-call "use-modules" modules)) + +;;;###autoload +(defun guix-devel-use-current-module () + "Use the current guile module." + (interactive) + (let ((module (guix-guile-current-module))) + (guix-devel-use-modules module) + (message "Using %s module." module))) + +(provide 'guix-devel) + +;;; guix-devel.el ends here diff --git a/emacs/guix-guile.el b/emacs/guix-guile.el index 87af192..ffa8848 100644 --- a/emacs/guix-guile.el +++ b/emacs/guix-guile.el @@ -24,6 +24,19 @@ ;;; Code: +(require 'geiser-guile) + +(defun guix-guile-current-module () + "Return string with current guile module. +Return nil, if current buffer does not define a module." + ;; Modified version of `geiser-guile--get-module'. + (save-excursion + (geiser-syntax--pop-to-top) + (when (or (re-search-backward geiser-guile--module-re nil t) + (looking-at geiser-guile--library-re) + (re-search-forward geiser-guile--module-re nil t)) + (match-string-no-properties 1)))) + (defun guix-guile-make-call-expression (proc &rest args) "Return \"(PROC ARGS ...)\" string. PROC and ARGS should be strings." -- 2.4.3