1 ;;; GNU Mes --- Maxwell Equations of Software
2 ;;; Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
4 ;;; This file is part of GNU Mes.
6 ;;; GNU Mes is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Mes is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
19 ;; The GNU project defaults. These are also the GNU Emacs defaults.
20 ;; Re-asserting theme here, however, as a courtesy for setups that use
23 ;; For writing GNU C code, see
24 ;; https://www.gnu.org/prep/standards/html_node/Writing-C.html
25 (c-mode . ((c-file-style . "gnu")
26 (indent-tabs-mode . nil)))
28 (makefile-mode . ((indent-tabs-mode . t)))
29 (asm-mode . ((indent-tabs-mode . t)))
31 (nil . ((indent-tabs-mode . nil)
36 ((geiser-active-implementations . (guile))
40 (defun prefix-dir-locals-dir (elt)
41 (concat (locate-dominating-file buffer-file-name ".dir-locals.el") elt))
43 (lambda (dir) (add-to-list 'geiser-guile-load-path dir))
45 #'prefix-dir-locals-dir
46 '("scripts" "module")))))))
48 (texinfo-mode . ((indent-tabs-mode . nil)
54 (let ((top (locate-dominating-file default-directory ".dir-locals.el"))))
56 (defun guile--manual-look-up (id mod)
57 (message "guile--manual-look-up id=%s => %s mod=%s" id (symbol-name id) mod)
58 (let ((info-lookup-other-window-flag
59 geiser-guile-manual-lookup-other-window-p))
60 (info-lookup-symbol (symbol-name id) 'scheme-mode))
61 (when geiser-guile-manual-lookup-other-window-p
62 (switch-to-buffer-other-window "*info*"))
63 (search-forward (format "%s" id) nil t))
65 (add-hook 'before-save-hook 'delete-trailing-whitespace nil t)
67 (defun guix-switch-profile (&optional profile)
68 "reset Emacs' environment by snarfing PROFILE/etc/profile"
70 (defun matches-in-string (regexp string)
71 "return a list of matches of REGEXP in STRING."
75 (while (string-match regexp string (match-end 0))
76 (push (or (match-string 1 string) (match-string 0 string)) matches)))
79 (interactive "fprofile: ")
80 (let* ((output (shell-command-to-string (concat "GUIX_PROFILE= /bin/sh -x " profile "/etc/profile")))
81 (exports (matches-in-string "^[+] export \\(.*\\)" output)))
82 (mapcar (lambda (line) (apply #'setenv (split-string line "="))) exports )))
84 (defun shell-args-to-string (&rest args)
85 (shell-command-to-string (mapconcat 'identity args " ")))
87 (defun as (string &optional arch)
88 (let* ((arch (or arch "--64"))
89 (asm (subst-char-in-string ?_ ?\s string))
90 (foo (message "asm:%S" asm))
91 (result (shell-args-to-string "as" arch (concat "<(echo '" asm "')")))
92 (disassembly (shell-args-to-string "objdump" "-d" "a.out"))
93 (foo (message "disassembly: %S" disassembly))
94 (match (string-match "^ 0:[\t]\\([^\t]*\\)" disassembly))
95 (code (match-string 1 disassembly))
96 (code (apply 'concat (split-string code " " t))))
100 (defun as-32 (point mark)
102 (let* ((string (buffer-substring point mark))
103 (code (as string "--32")))
107 (defun as-64 (point mark)
109 (let* ((string (buffer-substring point mark))
110 (code (as string "--64")))