.emacs.d

the most bloated Emacs config on this planet
git clone https://git.trogloxene.org/.emacs.d.git
Log | Files | Refs

init-kbd-func.el (3473B)


      1 ;;; init-kbd-func.el --- functions -*- lexical-binding: t -*-
      2 
      3 ;;; Commentary:
      4 
      5 ;;; Code:
      6 
      7 (defun open-init-file()
      8   "Open user's init.el file."
      9   (interactive)
     10   (find-file user-init-file))
     11 
     12 (defun my-scratch-buffer (&optional arg)
     13   "Switch to the *scratch* buffer.
     14 With a prefix ARG create a new *scratch* buffer."
     15   (interactive "P")
     16   (if arg
     17       (let ((buf (generate-new-buffer "*scratch*")))
     18         (switch-to-buffer buf)
     19         (funcall initial-major-mode))
     20     (scratch-buffer)))
     21 
     22 (when *is-windows*
     23   (defun restart-emacs ()
     24     "Restart emacs (for Windows)"
     25     (interactive)
     26     (save-some-buffers)
     27     (w32-shell-execute "open" "runemacs.exe")
     28     (kill-emacs)))
     29 
     30 (defun disable-truncate-lines ()
     31   (toggle-truncate-lines 1))
     32 
     33 (defun other-window-backward ()
     34   (interactive)
     35   (other-window -1))
     36 
     37 (defun query-replace-case-sensitive ()
     38   "Case-sensitive `query-replace'."
     39   (interactive)
     40   (let ((case-fold-search nil))
     41     (call-interactively #'query-replace)))
     42 
     43 (defun my-show-utc-time ()
     44   "Display current UTC time in echo area."
     45   (interactive)
     46   (message (format-time-string "%Y-%m-%d %H:%M UTC" nil t)))
     47 
     48 (defun my-straight-packages-count ()
     49   "Count how many straight.el package are currently installed."
     50   (interactive)
     51   (if (called-interactively-p 'interactive)
     52       (message (format "%s packages installed" (hash-table-count straight--profile-cache)))
     53     (hash-table-count straight--profile-cache)))
     54 
     55 (defun my-insert-straight-packages ()
     56   "Insert straight.el packages."
     57   (interactive)
     58   (dolist (item (sort (hash-table-keys straight--profile-cache)))
     59     (insert (format "- %s\n" item))))
     60 
     61 (defun org-cycle-parent-subtree()
     62   "Cycle parent org subtree."
     63   (interactive)
     64   (if (org-at-heading-p)
     65       (progn
     66         (org-up-heading 1)
     67         (org-cycle))
     68     (org-back-to-heading)
     69     (org-cycle)))
     70 
     71 (defun my-blog-find-file ()
     72   "Find blog file use denote-file-prompt."
     73   (interactive)
     74   (let* ((denote-directory my-blog-directory)
     75          (denote-excluded-files-regexp "_about")
     76          (file (denote-file-prompt)))
     77     (find-file file)))
     78 
     79 (defun my-blog-grep ()
     80   "Run `consult-grep' in `my-blog-directory'."
     81   (interactive)
     82   (consult-grep my-blog-directory))
     83 
     84 (defun my-org-table-align-all ()
     85   "Adjust all table in current buffer."
     86   (interactive)
     87   (org-table-map-tables 'org-table-align t))
     88 
     89 (defun org-align-description-list ()
     90   "Adjust all `::' in active region. "
     91   (interactive)
     92   (align-regexp (region-beginning) (region-end) "\\(\\s-*\\)::" 1 1 nil))
     93 
     94 (defun my-push-with-timestamp (directory)
     95   "Git add/commit/push, generate commit message."
     96   (let ((timestamp (format-time-string "%Y-%m-%d %H:%M:%S"))
     97         (default-directory directory))
     98     (message "Adding files...")
     99     (eshell-command "git add .")
    100     (message "Committing: %s" timestamp)
    101     (eshell-command (format "git commit -m \"Update: %s\"" timestamp))
    102     (message "Pushing to remote...")
    103     (let ((exit-code (eshell-command "git push")))
    104       (if (eq exit-code t)
    105           (message "Push may have failed or nothing to push, check *Messages* buffer for details")
    106         (message "Push successfully %s" timestamp)))))
    107 
    108 (defun my-note-push ()
    109   "Git add/commit/push in `~/org/my-org-note/'."
    110   (interactive)
    111   (my-push-with-timestamp "~/org/my-org-note/"))
    112 
    113 (defun my-org-publish ()
    114   "Git add/commit/push in `my-blog-directory'."
    115   (interactive)
    116   (my-push-with-timestamp my-blog-directory))
    117 
    118 (provide 'init-kbd-func)
    119 ;;; init-kbd-func.el ends here