From dc655490b630b2f3e53c566645d1d66e2d9a8086 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Thu, 2 Apr 2020 22:39:25 +0100 Subject: [PATCH 1/4] Add exwm integration within FG42 Signed-off-by: Sameer Rahmani --- .gitignore | 3 ++- Makefile | 9 ++++++++- lib/extensions/editor/init.el | 4 ++-- lib/extensions/serene/init.el | 2 +- lib/fg42/extension.el | 15 +++++++++++++++ share/applications/fg42.desktop | 4 ++-- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 41255ae..3a93feb 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ lib/**/*.elc *.elc tmp/ test-runner/ -.fpkg/ \ No newline at end of file +.fpkg/ +/fg42-wm \ No newline at end of file diff --git a/Makefile b/Makefile index e538a7d..b955d79 100644 --- a/Makefile +++ b/Makefile @@ -25,14 +25,21 @@ install: @cp ./config/fg42.user.el ${HOME}/.fg42.el @echo "Creating the link..." @echo "#! /bin/sh" > ./fg42 + @cp ./scripts/fg42-wm ./fg42-wm @echo "export FG42_HOME=$(shell pwd)" >> ./fg42 - @echo 'emacs --name FG42 --no-site-file --no-site-lisp --no-splash --title FG42 -l $$FG42_HOME/fg42-config.el "$$@"' >> ./fg42 + @echo "export FG42_HOME=$(shell pwd)" >> ./fg42-wm + @echo 'FG42_WM=false emacs --name FG42 --no-site-file --no-site-lisp --no-splash --title FG42 -l $$FG42_HOME/fg42-config.el "$$@"' >> ./fg42 + @echo 'FG42_WM=true emacs --name FG42 --no-site-file --no-site-lisp --no-splash --title FG42 -l $$FG42_HOME/fg42-config.el "$$@"' >> ./fg42-wm @chmod +x ./fg42 + @chmod +x ./fg42-wm @sudo rm -f /usr/local/bin/fg42 + @sudo rm -f /usr/local/bin/fg42-wm @sudo ln -s `pwd`/fg42 /usr/local/bin/fg42 + @sudo ln -s `pwd`/fg42-wm /usr/local/bin/fg42-wm @echo "Copying share files..." @sudo mkdir -p /usr/share/fg42/ @sudo cp -r ./share/* /usr/share/fg42/ + @sudo cp -r ./share/xsessions/fg42.desktop /usr/share/xsessions/ @echo " " @echo "------------------------------------------------------------------------------------" @echo "Make sure to install external dependencies of FG42. For more info checkout README.md" diff --git a/lib/extensions/editor/init.el b/lib/extensions/editor/init.el index fef0dfc..6f84e26 100644 --- a/lib/extensions/editor/init.el +++ b/lib/extensions/editor/init.el @@ -72,7 +72,7 @@ (ability which-key () (when (is-evil?) - (which-key-mode t))) + (which-key-mode t))) ;; enhance evil mode with space leader keybindings (ability space-keys (which-key) @@ -130,7 +130,7 @@ (ability highligh-current-line () "Highlights the current line." (global-hl-line-mode t)) - (ability flycheck () + (ability flycheck () "Check syntax on the fly using flycheck." (require 'flycheck) diff --git a/lib/extensions/serene/init.el b/lib/extensions/serene/init.el index 5bf68fc..8d84eae 100644 --- a/lib/extensions/serene/init.el +++ b/lib/extensions/serene/init.el @@ -4,7 +4,7 @@ ;;;###autoload (defun extensions/serene-initialize () - "Initialize the common Lisp extension." + "Initialize the Serene extension." (require 'extensions/serene/serene-simple-mode) (add-hook 'serene-simple-mode-hook #'paredit-mode) diff --git a/lib/fg42/extension.el b/lib/fg42/extension.el index 9aaa5b4..cfa00d5 100644 --- a/lib/fg42/extension.el +++ b/lib/fg42/extension.el @@ -56,6 +56,21 @@ to them. ,@body))) +(defmacro defability (name deps &optional docs &rest body) + "Define an ability with the given NAME, DEPS, DOCS and BODY. + +*deps* should be a list of abilities with the defined ability dependens +to them. + +*body* is a block of code which will run as the ability initializer code." + (declare (doc-string 3) (indent 2)) + ;; TODO: there's no point of using `if' in the quoted code. evaluate + ;; the `if' in compile time and return nil or evalute the body. + `(if (active-ability? (intern ,(symbol-name name))) + (when (null (delq t (mapcar 'active-ability? (quote ,deps)))) + ,@body))) + + (defmacro extension (name &rest args) "A simple DSL to define new fg42 extension by given NAME and ARGS." ;(declare (doc-string 1) (indent 1)) diff --git a/share/applications/fg42.desktop b/share/applications/fg42.desktop index 24c8dea..5619721 100644 --- a/share/applications/fg42.desktop +++ b/share/applications/fg42.desktop @@ -2,12 +2,12 @@ Encoding=UTF-8 Name=FG42 GenericName=FG42 -Comment=An Emacs base IDE for emacs lovers. +Comment=An Emacs base editor for true believers MimeType=text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-java;application/x-shellscript;text/x-c;text/x-c++;text/x-ruby;text/x-python;text/x-clojure;text/css;text/html;text/x-javascript; Type=Application Terminal=false Categories=Development;TextEditor; StartupWMClass=FG42 Exec=/usr/local/bin/fg42 %F -Icon=kuso +Icon=fg42 Version=2.67 \ No newline at end of file From 814910a379e36e02b6c29745518f935fc08c5227 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Thu, 2 Apr 2020 22:39:43 +0100 Subject: [PATCH 2/4] Add the untracked files Signed-off-by: Sameer Rahmani --- lib/fg42/wm.el | 149 +++++++++++++++++++++++++++++++++++ scripts/fg42-wm | 20 +++++ share/xsessions/fg42.desktop | 15 ++++ 3 files changed, 184 insertions(+) create mode 100644 lib/fg42/wm.el create mode 100644 scripts/fg42-wm create mode 100644 share/xsessions/fg42.desktop diff --git a/lib/fg42/wm.el b/lib/fg42/wm.el new file mode 100644 index 0000000..07ad344 --- /dev/null +++ b/lib/fg42/wm.el @@ -0,0 +1,149 @@ +;;; WM --- Enables FG42 as a window manager using EXWM +;;; Commentary: +;;; Code: +(require 'fpkg) + + +(defmacro when-wm (&rest body) + "Run the BODY only if in wm mode." + (if (string= (getenv "FG42_WM") "true") + `(progn ,@body) + nil)) + + +(defmacro when-not-wm (&rest body) + "Run the BODY only if in wm mode." + (if (string= (getenv "FG42_WM") "true") + nil + `(progn ,@body))) + + +(defun disable-nlinum () + "Disables nlinum and fringe-mode." + (fringe-mode 1) + (nlinum-mode -1)) + + +(defun run-program (path) + "Execute the program at the given PATH." + (start-process-shell-command path nil path)) + + +(defun run-program-in-xterm (path &optional name) + "Execute the program at the given PATH via xterm with the given NAME." + (run-program (concat "xterm -e " path))) + + +(defun rename-x-window (&optional name) + "Rename the current buffer to NAME." + (interactive) + (let ((new-name (or name (read-string "New name: ")))) + (exwm-workspace-rename-buffer new-name))) + + +(defability wm () + "Window manager ability for FG42." + (depends-on 'exwm) + + (defun initialize-wm () + (when-wm + (require 'exwm) + (require 'exwm-config) + (require 'exwm-systemtray) + (exwm-config-ido) + ;; Set the initial number of workspaces (they can also be created later). + (setq exwm-workspace-number 10) + + ;; All buffers created in EXWM mode are named "*EXWM*". You may want to + ;; change it in `exwm-update-class-hook' and `exwm-update-title-hook', which + ;; are run when a new X window class name or title is available. Here's + ;; some advice on this topic: + ;; + Always use `exwm-workspace-rename-buffer` to avoid naming conflict. + ;; + For applications with multiple windows (e.g. GIMP), the class names of + ; all windows are probably the same. Using window titles for them makes + ;; more sense. + ;; In the following example, we use class names for all windows except for + ;; Java applications and GIMP. + (add-hook 'exwm-update-class-hook + (lambda () + (unless (or (string-prefix-p "sun-awt-X11-" exwm-instance-name) + (string= "gimp" exwm-instance-name)) + (exwm-workspace-rename-buffer exwm-class-name)))) + (add-hook 'exwm-update-title-hook + (lambda () + (when (or (not exwm-instance-name) + (string-prefix-p "sun-awt-X11-" exwm-instance-name) + (string= "gimp" exwm-instance-name)) + (exwm-workspace-rename-buffer exwm-title)))) + + + ;; Global keybindings can be defined with `exwm-input-global-keys'. + ;; Here are a few examples: + (setq exwm-input-global-keys + `( + ;; Bind "s-r" to exit char-mode and fullscreen mode. + ([?\s-r] . exwm-reset) + ;; Bind "s-w" to switch workspace interactively. + ([?\s-w] . exwm-workspace-switch) + ;; Bind "s-0" to "s-9" to switch to a workspace by its index. + ,@(mapcar (lambda (i) + `(,(kbd (format "s-%d" i)) . + (lambda () + (interactive) + (exwm-workspace-switch-create ,i)))) + (number-sequence 0 9)) + ;; Bind "s-&" to launch applications ('M-&' also works if the output + ;; buffer does not bother you). + ([?\s-d] . (lambda (command) + (interactive (list (read-shell-command "$ "))) + (start-process-shell-command command nil command))) + ;; Bind "s-" to "slock", a simple X display locker. + ([s-f2] . (lambda () + (interactive) + (start-process "" nil "/usr/bin/slock"))))) + ;; To add a key binding only available in line-mode, simply define it in + ;; `exwm-mode-map'. The following example shortens 'C-c q' to 'C-q'. + (define-key exwm-mode-map [?\C-q] #'exwm-input-send-next-key) + + ;; The following example demonstrates how to use simulation keys to mimic + ;; the behavior of Emacs. The value of `exwm-input-simulation-keys` is a + ;; list of cons cells (SRC . DEST), where SRC is the key sequence you press + ;; and DEST is what EXWM actually sends to application. Note that both SRC + ;; and DEST should be key sequences (vector or string). + (setq exwm-input-simulation-keys + '( + ;; movement + ([?\C-b] . [left]) + ([?\M-b] . [C-left]) + ([?\C-f] . [right]) + ([?\M-f] . [C-right]) + ([?\C-p] . [up]) + ([?\C-n] . [down]) + ([?\C-a] . [home]) + ([?\C-e] . [end]) + ([?\M-v] . [prior]) + ([?\C-v] . [next]) + ([?\C-d] . [delete]) + ([?\C-k] . [S-end delete]) + ;; cut/paste. + ([?\C-w] . [?\C-x]) + ([?\M-w] . [?\C-c]) + ([?\C-y] . [?\C-v]) + ;; search + ([?\C-s] . [?\C-f]))) + + ;; You can hide the minibuffer and echo area when they're not used, by + ;; uncommenting the following line. + ;(setq exwm-workspace-minibuffer-position 'bottom) + + ;; Do not forget to enable EXWM. It will start by itself when things are + ;; ready. You can put it _anywhere_ in your configuration. + (exwm-enable) + (exwm-systemtray-enable) + + (with-ability nlinum + (add-hook 'exwm-mode-hook 'disable-nlinum))))) + + +(provide 'fg42/wm) +;;; wm.el ends here diff --git a/scripts/fg42-wm b/scripts/fg42-wm new file mode 100644 index 0000000..96e8e58 --- /dev/null +++ b/scripts/fg42-wm @@ -0,0 +1,20 @@ +#! /bin/sh + +# Disable access control for the current user. +xhost +SI:localuser:$USER + +# Make Java applications aware this is a non-reparenting window manager. +export _JAVA_AWT_WM_NONREPARENTING=1 + +# Set default cursor. +xsetroot -cursor_name left_ptr + +# Set keyboard repeat rate. +xset r rate 200 60 + +~/.xinitrc +# Uncomment the following block to use the exwm-xim module. +#export XMODIFIERS=@im=exwm-xim +#export GTK_IM_MODULE=xim +#export QT_IM_MODULE=xim +#export CLUTTER_IM_MODULE=xim diff --git a/share/xsessions/fg42.desktop b/share/xsessions/fg42.desktop new file mode 100644 index 0000000..df91afe --- /dev/null +++ b/share/xsessions/fg42.desktop @@ -0,0 +1,15 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=FG42 +GenericName=FG42 +Comment=An Emacs base editor and WM for emacsians +MimeType=text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-java;application/x-shellscript;text/x-c;text/x-c++;text/x-ruby;text/x-python;text/x-clojure;text/css;text/html;text/x-javascript; +Type=Application +Terminal=false +Categories=Development;TextEditor; +StartupWMClass=FG42 +Exec=/usr/local/bin/fg42-wm +Icon=fg42 +Version=2.67 +X-LightDM-DesktopName=FG42 +DesktopNames=FG42 From eb79f09191d84ec195219c92028bab34f456aa02 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Fri, 3 Apr 2020 12:59:16 +0100 Subject: [PATCH 3/4] Update fg42-wm to contain better keyboard repeat rate --- scripts/fg42-wm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/fg42-wm b/scripts/fg42-wm index 96e8e58..87338ad 100644 --- a/scripts/fg42-wm +++ b/scripts/fg42-wm @@ -10,9 +10,9 @@ export _JAVA_AWT_WM_NONREPARENTING=1 xsetroot -cursor_name left_ptr # Set keyboard repeat rate. -xset r rate 200 60 +xset r rate 400 30 -~/.xinitrc +$HOME/.xinitrc # Uncomment the following block to use the exwm-xim module. #export XMODIFIERS=@im=exwm-xim #export GTK_IM_MODULE=xim From e717dfef6fc518989c0f04cfa153fb81da4bc71a Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Fri, 3 Apr 2020 16:40:18 +0100 Subject: [PATCH 4/4] Add couple of keybinding to line mode of wm --- lib/fg42/wm.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/fg42/wm.el b/lib/fg42/wm.el index 07ad344..052c2d5 100644 --- a/lib/fg42/wm.el +++ b/lib/fg42/wm.el @@ -83,6 +83,7 @@ `( ;; Bind "s-r" to exit char-mode and fullscreen mode. ([?\s-r] . exwm-reset) + ([?\s-g] . keyboard-quit) ;; Bind "s-w" to switch workspace interactively. ([?\s-w] . exwm-workspace-switch) ;; Bind "s-0" to "s-9" to switch to a workspace by its index. @@ -125,6 +126,12 @@ ([?\C-v] . [next]) ([?\C-d] . [delete]) ([?\C-k] . [S-end delete]) + ;; navigation + ([?\C-c b] . [\M-left]) + ([?\C-c f] . [\M-right]) + + ;; Actions + ([?\C-c w] . [\C-w]) ;; cut/paste. ([?\C-w] . [?\C-x]) ([?\M-w] . [?\C-c])