This repository has been archived by the owner on Mar 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathmatrix-client-standalone.el.sh
executable file
·160 lines (122 loc) · 4.48 KB
/
matrix-client-standalone.el.sh
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
#;;; Bash script
#;; This file can be executed directly as a "standalone" Emacs Matrix
#;; client that does not load any user configuration files. The Bash
#;; process substitution trick above was inspired by:
#;; https://superuser.com/a/821624
# * Defaults
recipe_part=":fetcher github :repo \"alphapapa/matrix-client.el\""
custom_file_dir="~/.config/"
# * Functions
function die {
echo "$@" >&2
exit 1
}
function usage {
cat <<EOF
This script launches matrix-client.el with a mostly clean Emacs configuration.
It's only "mostly" clean because it uses the local ELPA package
installation directory. This allows you to, e.g. load themes you
already have installed, and it means that, after running this script,
matrix-client will be usable in your main Emacs config.
Options:
--debug Enable debug-on-error in Emacs
--help You're lookin' at it
--branch BRANCH Use repo BRANCH instead of master
--local PATH Use git repo at PATH instead of official one on GitHub (helpful for development)
--upgrade Upgrade matrix-client.el and required dependency upgrades before connecting
EOF
}
# * Args
while [[ $1 ]]
do
[[ $1 == --debug ]] && debug="(setq debug-on-error t) (setq matrix-log t)"
[[ $1 == --help ]] && usage && exit
[[ $1 == --branch ]] && {
shift
branch=":branch \"$1\""
}
[[ $1 == --local ]] && {
shift
[[ -d $1/.git ]] && [[ -r $1/.git ]] || die "Not a readable directory (should be a Git repo): $1"
recipe_part=":fetcher git :url ,(expand-file-name \"$1\")"
}
[[ $1 == --upgrade ]] && upgrade="(setq upgrade-matrix-client t) (setq quelpa-update-melpa-p t)"
shift
done
# * Main
# Find end of bash script
bash_end_line=$((2 + $(grep -n -m 1 -x "exit" "$0" \
| grep -o -E '[[:digit:]]+')))
# Run Emacs
emacs -q --insert <(tail -n +$bash_end_line "$0") --eval="(progn
(defvar upgrade-matrix-client nil)
(defvar quelpa-update-melpa-p nil)
(setq user-init-file (expand-file-name \"matrix-client-standalone.el\" \"$custom_file_dir\"))
(when (file-readable-p user-init-file)
(load user-init-file))
(setq recipe \`(matrix-client $recipe_part $branch
:files (:defaults \"logo.png\" \"matrix-client-standalone.el.sh\")))
$upgrade $debug
(eval-buffer))"
exit
;;; # * matrix-client-standalone.el
;; Misc settings
(setf frame-resize-pixelwise t
window-resize-pixelwise t)
(setq load-prefer-newer t)
(setq tool-bar-mode nil)
(setq scroll-conservatively 100)
(setq scroll-step 100)
(set-fringe-mode 0)
(scroll-bar-mode -1)
;; Improve default completion
(setq completion-ignore-case t)
(setq read-buffer-completion-ignore-case t)
(setq completion-cycle-threshold 1)
(setq completions-format 'vertical)
;; Switch buffer command
(global-set-key (kbd "C-<tab>") #'matrix-client-switch-buffer)
(global-set-key [f1] #'matrix-client-switch-to-notifications-buffer)
;;;# package.el
(require 'package)
(setq package-menu-async nil)
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")))
(package-initialize)
;;;# Quelpa
;; Install Quelpa if necessary.
(unless (require 'quelpa-use-package nil t)
(defun install-quelpa ()
(package-install 'quelpa-use-package)
(require 'quelpa-use-package nil t))
(add-hook 'package--post-download-archives-hook #'install-quelpa)
(package-list-packages))
;; Install/upgrade Matrix Client. Quelpa makes it very difficult to force an upgrade. It says if
;; you add ":upgrade t", it will, but it doesn't work. So we have to bind `current-prefix-arg'.
(let ((current-prefix-arg upgrade-matrix-client))
(quelpa recipe))
;;;# matrix-client
(use-package matrix-client
:custom
(matrix-client-show-images t)
(matrix-client-show-room-avatars t)
(matrix-client-mark-modified-rooms t))
;;;;# Connect
(setf print-level 1 print-length 1 print-circle t
debugger-print-function #'prin1)
(add-hook 'matrix-client-setup-room-buffer-hook
(lambda (&rest _ignore)
(setq mode-line-format nil)))
(with-selected-frame
(call-interactively #'matrix-client-frame)
(delete-other-frames))
(add-hook 'matrix-after-initial-sync-hook #'matrix-client-room-list)
;; Bind some keys after loading matrix-client.
;; One of the cool things about `hippie-expand' is that it dynamically
;; expands file paths, making it helpful for the /upload command.
(define-key matrix-client-mode-map (kbd "M-/") #'hippie-expand)
;; Local Variables:
;; eval: (aggressive-indent-mode -1)
;; eval: (flycheck-mode -1)
;; End: