~hristoast/dot-emacs

025af3d65813fb913d4869d72a94be48050d3e4d — Hristos N. Triantafillou 3 months ago cdffcaa
Prefix my functions
2 files changed, 40 insertions(+), 25 deletions(-)

M lib/functions.el
M lib/keybindings.el
M lib/functions.el => lib/functions.el +36 -14
@@ 3,42 3,47 @@
;; Extra convenience functions.
;;; Code:

(defun build-project ()
(defun hristoast-build-project ()
  "Compile the current project."
  (interactive)
  (defvar compilation-read-command nil)
  (call-interactively 'compile))

(defun do-func-to-marked-region (func)
  "Do (FUNC) on a region forward and in reverse."
(defun hristoast--do-func-to-marked-region (func)
  "Do FUNC on a region forward and in reverse."
  (let ((mark (mark))
        (point (point)))
    (if (> mark point)
        (funcall func point mark)
      (funcall func mark point))))

(defun indent-appropriately ()
(defun hristoast-indent-appropriately ()
  "Appropriately indent the current line or region."
  (interactive)
  (if mark-active
      (do-func-to-marked-region 'indent-region)
      (hristoast--do-func-to-marked-region 'indent-region)
    (indent-according-to-mode)))

(defun toggle-comment ()
(defun hristoast-toggle-comment ()
  "Toggle comments on the current line or highlighted region."
  (interactive)
  (if mark-active
    (do-func-to-marked-region 'comment-or-uncomment-region)
    (hristoast--do-func-to-marked-region 'comment-or-uncomment-region)
    (comment-or-uncomment-region
     (line-beginning-position)
     (line-end-position))))

(defun hristoast-toggle-fc-and-ws ()
  "Toggle displaying the fill column indicator and `whitespace-mode' in one handy function."
  (interactive)
  (display-fill-column-indicator-mode 'toggle)
  (whitespace-mode 'toggle))

(defun hristoast-run-async-shell-command-maybe-with-env (cmd env-key env-val)
  "Asyncronously run CMD with ENV-KEY=ENV-VAL set beforehand if need be."
  (progn
    (when (and env-key env-val)
      (setenv env-key env-val))
    (async-shell-command cmd)))
  (when (and env-key env-val)
    (setenv env-key env-val))
  (async-shell-command cmd))

(defun hristoast-generate-openmw-compile-commands-json ()
  "A helper for generating a compile-commands.json file for using LSP with OpenMW."


@@ 57,8 62,25 @@
           (concat " && make -j" (number-to-string (+ 1 (string-to-number (shell-command-to-string "nproc"))))))
   nil nil))

(defun launch-thing (thing)
  "Open 'THING', which should be some sort of X program."
  (start-process "" nil thing))
(defun hristoast-regenerate-openmw-compile-commands-json ()
  "A helper for incrementally generating a compile-commands.json file for using LSP with OpenMW."
  (interactive)
  (hristoast-run-async-shell-command-maybe-with-env
   (concat "cd ~/src/openmw/build && cmake -DCMAKE_BUILD_TYPE=Debug .."
           (concat " && bear make -j" (number-to-string (+ 1 (string-to-number (shell-command-to-string "nproc")))))
           " && mv -fv compile_commands.json ..")
   "CMAKE_PREFIX_PATH" "/opt/build-openmw/osg-openmw:/opt/build-openmw/bullet"))

(defun hristoast-recompile-openmw-debug ()
  "A helper for incrementally compiling a debug build of OpenMW."
  (interactive)
  (hristoast-run-async-shell-command-maybe-with-env
   (concat "cd ~/src/openmw/build && cmake -DCMAKE_BUILD_TYPE=Debug .."
           (concat " && make -j" (number-to-string (+ 1 (string-to-number (shell-command-to-string "nproc"))))))
   nil nil))

;; (defun hristoast-launch-thing (thing)
;;   "Open 'THING', which should be some sort of X program."
;;   (start-process "" nil thing))

;;; functions.el ends here

M lib/keybindings.el => lib/keybindings.el +4 -11
@@ 6,12 6,12 @@
;; Insert a newline, then indent according to major mode
(global-set-key (kbd "RET") 'newline-and-indent)
;; Build, compile, that stuff
(global-set-key (kbd "<f5>") 'build-project)
(global-set-key (kbd "<f5>") 'hristoast-build-project)
;; Make undo work like other editors
(global-unset-key (kbd "C-/"))
(global-set-key (kbd "M-z") 'undo)
;; Better comment-toggling
(global-set-key (kbd "M-/") 'toggle-comment)
(global-set-key (kbd "M-/") 'hristoast-toggle-comment)
;; Make text bigger
(global-set-key (kbd "M-=") 'text-scale-increase)
(global-set-key (kbd "<f9>") 'text-scale-increase)


@@ 31,7 31,7 @@
(global-set-key (kbd "C-c u w") 'upcase-word)
(global-set-key (kbd "C-x u") 'upcase-region)
(global-set-key (kbd "C-x t m") 'menu-bar-mode)
(global-set-key (kbd "TAB") 'indent-appropriately)
(global-set-key (kbd "TAB") 'hristoast-indent-appropriately)
(global-set-key (kbd "C-x C-v") 'clipboard-yank)
(global-set-key (kbd "C-S-^") 'enlarge-window)
(global-set-key (kbd "C-%") 'shrink-window)


@@ 43,14 43,7 @@
(global-set-key (kbd "<backtab>") 'hs-show-all)
(global-set-key (kbd "C-x f") 'hs-hide-block)
(global-set-key (kbd "C-x c") 'hs-show-block)

(defun toggle-fc-and-ws ()
  "Toggle displaying the fill column indicator and `whitespace-mode' in one handy function."
  (interactive)
  (display-fill-column-indicator-mode 'toggle)
  (whitespace-mode 'toggle))

(global-set-key (kbd "<f11>") 'toggle-fc-and-ws)
(global-set-key (kbd "<f11>") 'hristoast-toggle-fc-and-ws)

;; Kill this buffer!
(substitute-key-definition 'kill-buffer 'kill-buffer-and-window global-map)