-
Notifications
You must be signed in to change notification settings - Fork 11
/
hinit.el
106 lines (91 loc) · 4.03 KB
/
hinit.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
;;; hinit.el --- Standard initializations for GNU Hyperbole -*- lexical-binding: t; -*-
;;
;; Author: Bob Weiner
;;
;; Orig-Date: 1-Oct-91 at 02:32:51
;; Last-Mod: 29-Oct-23 at 10:07:47 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 1991-2023 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of GNU Hyperbole.
;;; Commentary:
;;; Code:
;;; ************************************************************************
;;; Public variables
;;; ************************************************************************
(defvar hyperb:user-email nil
"Email address for the current user. Set automatically by `hyperb:init'.")
;;; ************************************************************************
;;; Other required Elisp libraries
;;; ************************************************************************
;; Note: hibtypes must be loaded before hui-menu or klink defib priority
;; could be set improperly.
(eval-and-compile (mapc #'require '(hvar hibtypes hui-menu hui-mouse hypb hui hui-mini hbmap)))
;;; ************************************************************************
;;; Public functions
;;; ************************************************************************
(unless (fboundp 'br-in-browser)
;; Then the OO-Browser is not loaded, so we can never be within the
;; browser. Define this as a dummy function that always returns nil
;; until the OO-Browser is ever loaded.
(defun br-in-browser ()
"Always return nil since the OO-Browser is not loaded."
nil))
;;;###autoload
(defun hyperb:init-menubar ()
"Add a pulldown menu for Hyperbole after Emacs is initialized."
(interactive)
(unless (featurep 'infodock)
;; Initialize now since Emacs startup has finished.
(if after-init-time (hyperbole-menubar-menu)
;; Defer initialization until after Emacs startup. This really is needed.
(add-hook 'after-init-hook #'hyperbole-menubar-menu))
;; Avoid returning the large Hyperbole menu.
nil))
;;; ************************************************************************
;;; Menu Support Functions
;;; ************************************************************************
;;;###autoload
(defmacro hui-menu-remove (menu-sym &optional keymap)
"Remove MENU-SYM from menubars generated by optional KEYMAP or the `global-map'."
`(prog1
(define-key (or ,keymap global-map) [menu-bar ,menu-sym] nil)
;; Force a menu-bar update.
(force-mode-line-update)))
;;; ************************************************************************
;;; Private functions
;;; ************************************************************************
(defun hyperb:check-dir-user ()
"Ensure `hbmap:dir-user' exists and is writable or signal an error."
(if (or (null hbmap:dir-user) (not (stringp hbmap:dir-user))
(and (setq hbmap:dir-user (file-name-as-directory
(expand-file-name hbmap:dir-user)))
(file-directory-p hbmap:dir-user)
(not (file-writable-p (directory-file-name hbmap:dir-user)))))
(error
"(hyperb:init): `hbmap:dir-user' must be a writable directory name"))
(let ((hbmap:dir-user (directory-file-name hbmap:dir-user)))
(or (file-directory-p hbmap:dir-user) ;; Exists and is writable.
(let* ((parent-dir (file-name-directory
(directory-file-name hbmap:dir-user))))
(cond
((not (file-directory-p parent-dir))
(error
"(hyperb:init): `hbmap:dir-user' parent dir does not exist"))
((not (file-writable-p parent-dir))
(error
"(hyperb:init): `hbmap:dir-user' parent directory not writable"))
((or (if (fboundp 'make-directory)
(progn (make-directory hbmap:dir-user) t))
(hypb:call-process-p "mkdir" nil nil hbmap:dir-user))
(or (file-writable-p hbmap:dir-user)
(or (progn (hypb:chmod '+ 700 hbmap:dir-user)
(file-writable-p hbmap:dir-user))
(error "(hyperb:init): Can't write to 'hbmap:dir-user'"))))
(t (error "(hyperb:init): `hbmap:dir-user' create failed"))))))
t)
(provide 'hinit)
;;; hinit.el ends here