Files
.emacs.d/lisp/init-kbd-func.el

138 lines
4.2 KiB
EmacsLisp

;;; init-kbd-func.el --- functions for keybindings -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(defun open-init-file()
"Open user's init.el file in ~/.emacs.d ."
(interactive)
(find-file "~/.emacs.d/init.el"))
(when *is-windows*
(defun restart-emacs ()
"Restart emacs (for Windows)"
(interactive)
(save-some-buffers)
(w32-shell-execute "open" "runemacs.exe")
(kill-emacs)))
(defun my/jinx-smart-toggle ()
"Toggle jinx-mode smartly.
Disable jinx-mode if it's enable and global-jinx-mode is disable , otherwise toggle global-jinx-mode."
(interactive)
(unless (featurep 'jinx)
(require 'jinx))
(let ((local-on (bound-and-true-p jinx-mode))
(global-on (bound-and-true-p global-jinx-mode)))
(cond
((and local-on (not global-on))
(message "disable jinx-mode in current buffer")
(jinx-mode -1))
(t
(if global-on
(progn
(message "disable global-jinx-mode")
(global-jinx-mode -1))
(progn
(message "enable global-jinx-mode")
(global-jinx-mode 1)))))))
(defun duplicate-and-move-to-next-line()
"Duplicate current line and move to next line."
(interactive)
(progn
(duplicate-line)
(next-line)))
(defun popper-toggle-type-delete-other-window()
"Toggle type of popper window and delete other window."
(interactive)
(popper-toggle-type)
(delete-other-windows))
(defun consult-directory-externally (file)
"Open FILE externally using the default application of the system."
(interactive "fOpen externally: ")
(if (and (eq system-type 'windows-nt)
(fboundp 'w32-shell-execute))
(shell-command-to-string (encode-coding-string (replace-regexp-in-string "/" "\\\\"
(format "explorer.exe %s" (file-name-directory (expand-file-name file))))
'gbk))
(call-process (pcase system-type
('darwin "open")
('cygwin "cygstart")
(_ "xdg-open"))
nil 0 nil
(file-name-directory (expand-file-name file)))))
(defun consult-fd-global ()
"Search for all files use fd"
(interactive)
(let ((consult-fd-args "fd -H -I -i -c never --full-path")
(default-directory "~/"))
(consult-fd)))
(defun my-open-current-directory ()
"Open current directory in default file explorer."
(interactive)
(consult-directory-externally default-directory))
(defun org-cycle-parent-subtree()
"Cycle parent org subtree."
(interactive)
(if (org-at-heading-p)
(progn
(org-up-heading 1)
(org-cycle))
(org-back-to-heading)
(org-cycle)))
(defun consult-org-ripgrep ()
"Search in org files use consult-ripgrep."
(interactive)
(consult-ripgrep (unless *is-windows*
'("~/org/my-org-note/" "~/org/hugo/this-is-my-blog/all-blog.org"))))
(defun my-denote-journal-path-to-existing-entry (&optional date interval)
"Return the path of current denote journal if it exists, otherwise return nil."
(require 'denote-journal)
(let* ((internal-date (denote-journal--date-in-interval-p (or date (current-time)) interval))
(files (denote-journal--get-entry internal-date interval)))
(if files
(denote-journal-select-file-prompt files))))
(defun my-denote-journal-open-entry ()
"Open current denote-journal entry."
(interactive)
(if (my-denote-journal-path-to-existing-entry)
(find-file (my-denote-journal-path-to-existing-entry))
(message "No journal for today yet")))
(defun org-table-align-all ()
"Ajust all table in current buffer."
(interactive)
(save-excursion
(goto-char (point-min))
(org-table-map-tables 'org-table-align t)))
(defun org-align-description-list ()
"Ajust all `::' in active region. "
(interactive)
(align-regexp (region-beginning) (region-end) "\\(\\s-*\\)::" 1 1 nil))
(defun switch-to-emms-playlist()
"Switch to emms playlist."
(interactive)
(switch-to-buffer "*EMMS Playlist*"))
(defun my/dired-next-line()
"Move to forward line in dired buffer"
(interactive)
(forward-line 1)
(dired-move-to-filename))
(provide 'init-kbd-func)
;;; init-kbd-func.el ends here