| 1 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2 |
; ; |
| 3 |
; This file is part of Frama-C. ; |
| 4 |
; ; |
| 5 |
; Copyright (C) 2007-2022 ; |
| 6 |
; CEA (Commissariat à l'énergie atomique et aux énergies ; |
| 7 |
; alternatives) ; |
| 8 |
; ; |
| 9 |
; you can redistribute it and/or modify it under the terms of the GNU ; |
| 10 |
; Lesser General Public License as published by the Free Software ; |
| 11 |
; Foundation, version 2.1. ; |
| 12 |
; ; |
| 13 |
; It is distributed in the hope that it will be useful, ; |
| 14 |
; but WITHOUT ANY WARRANTY; without even the implied warranty of ; |
| 15 |
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; |
| 16 |
; GNU Lesser General Public License for more details. ; |
| 17 |
; ; |
| 18 |
; See the GNU Lesser General Public License version 2.1 ; |
| 19 |
; for more details (enclosed in the file licenses/LGPLv2.1). ; |
| 20 |
; ; |
| 21 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 22 |
|
| 23 |
;; *** Auxiliary definitions for Frama-C Emacs files *** |
| 24 |
;; |
| 25 |
;; This file is automatically included by both 'frama-c-dev.el' and |
| 26 |
;; 'frama-c-recommended.el'. You do not need to do anything here. |
| 27 |
;; |
| 28 |
|
| 29 |
;; Macro to avoid crashing if the required file does not exist |
| 30 |
(defmacro safe-require (symbol &rest body) |
| 31 |
`(condition-case nil |
| 32 |
(progn |
| 33 |
(require ',symbol) |
| 34 |
,@body) |
| 35 |
(error (message (format "Require NOT available: %s" ',symbol)) nil))) |
| 36 |
|
| 37 |
;; Macro to avoid crashing if the library to load does not exist |
| 38 |
(defun safe-load-library (path) |
| 39 |
(condition-case nil |
| 40 |
(load-library path) |
| 41 |
(error (message (format "Library NOT available: %s" path)) nil))) |
| 42 |
|
| 43 |
;; Add opam emacs directory to the load-path |
| 44 |
(condition-case nil |
| 45 |
(progn nil (setq opam-share (substring |
| 46 |
(shell-command-to-string |
| 47 |
"opam config var share 2> /dev/null") 0 -1)) |
| 48 |
(add-to-list 'load-path (concat opam-share "/emacs/site-lisp"))) |
| 49 |
(error (message "Error configuring OPAM, check your installation.") nil)) |
| 50 |
|
| 51 |
;; Setup environment variables using OPAM |
| 52 |
;; This helps when compiling OCaml installed via OPAM directly from Emacs |
| 53 |
(condition-case nil |
| 54 |
(dolist (var (car (read-from-string (shell-command-to-string |
| 55 |
"opam config env --sexp")))) |
| 56 |
(setenv (car var) (cadr var))) |
| 57 |
(error (message "Error configuring OPAM sexp, check your installation.") nil)) |
| 58 |
|
| 59 |
;; One of the `opam config env` variables is PATH. Update `exec-path` to that. |
| 60 |
(setq exec-path (split-string (getenv "PATH") path-separator)) |