88 lines
3.1 KiB
EmacsLisp
88 lines
3.1 KiB
EmacsLisp
;;; 99-misc.el --- My miscellaneous functions. -*- no-byte-compile: t; lexical-binding: t; -*-
|
|
|
|
;;; Description:
|
|
;; This file contains my miscellaneous functions and their key binding code.
|
|
;; Some of those functions were written by me, some of them are taken from the
|
|
;; internet.
|
|
|
|
;;; Code:
|
|
|
|
(defun my-resize-margins-to-fill ()
|
|
"Set the current buffer margins so that its width is equal to the fill
|
|
column."
|
|
(interactive)
|
|
(let ((margin-size (/ (- (frame-width) fill-column) 2)))
|
|
(set-window-margins nil margin-size margin-size)))
|
|
|
|
(defun my-reset-margins ()
|
|
"Removes margins from the current buffer."
|
|
(interactive)
|
|
(set-window-margins nil nil nil))
|
|
|
|
(defun my-insert-buffer-name ()
|
|
"Inserts the name of the current buffer at point."
|
|
(interactive)
|
|
(let ((name (buffer-name)))
|
|
(insert name)))
|
|
|
|
(defun my-create-org-fc-word-card ()
|
|
"Inserts and initialzes an org-fc double card with a word and its
|
|
translation at point."
|
|
(interactive)
|
|
(let* ((engw (read-from-minibuffer "Enter English word: "))
|
|
(rusw (read-from-minibuffer "Enter Russian word: ")))
|
|
(insert "* " engw)
|
|
(newline)
|
|
(insert rusw)
|
|
(previous-line)
|
|
(org-fc-type-double-init)))
|
|
|
|
(keymap-set org-mode-map "C-c C-n" 'my-create-org-fc-word-card)
|
|
|
|
(setq margins-map (make-sparse-keymap))
|
|
(keymap-set margins-map "f" 'my-resize-margins-to-fill)
|
|
(keymap-set margins-map "r" 'my-reset-margins)
|
|
|
|
(keymap-set mode-specific-map "C-m" margins-map)
|
|
(keymap-set mode-specific-map "b" 'my-insert-buffer-name)
|
|
|
|
(defun my-preview-macro-expansion (arg)
|
|
"Previews the expansion of a macro in a temporary window.
|
|
|
|
If the prefix argument ARG is non-nil, a full recursive
|
|
macroexpansion (`macroexpand-all') will we performed, otherwise only one
|
|
macroexpansion step (`macroexpand-1') will be done.
|
|
|
|
If there is an active region selected, only its contents will be read
|
|
for the expansion. See also `pp-macroexpand-expression'."
|
|
(interactive "P")
|
|
(let ((obj))
|
|
(if (use-region-p)
|
|
(setq obj
|
|
(with-demoted-errors
|
|
"Failed to read form: %S"
|
|
(read (buffer-substring (region-beginning) (region-end)))))
|
|
(save-excursion
|
|
(setq obj (with-demoted-errors
|
|
"Failed to read form: %S"
|
|
(read (current-buffer))))))
|
|
(if obj
|
|
(let ((inhibit-read-only t))
|
|
(with-current-buffer-window "*Macro Expansion*" nil nil
|
|
(if arg
|
|
(pp (macroexpand-all obj))
|
|
(pp (macroexpand-1 obj)))
|
|
(emacs-lisp-mode)
|
|
(keymap-local-set (kbd "q") #'quit-window))
|
|
(select-window (get-buffer-window "*Macro Expansion*"))))))
|
|
|
|
(with-eval-after-load 'embark
|
|
(setq embark-pre-action-hooks
|
|
(add-to-list 'embark-pre-action-hooks '(my-preview-macro-expansion embark--beginning-of-target)))
|
|
(keymap-set embark-expression-map "m" 'my-preview-macro-expansion)
|
|
(keymap-set embark-expression-map "M" 'pp-macroexpand-expression)
|
|
(keymap-set embark-defun-map "m" 'my-preview-macro-expansion)
|
|
(keymap-set embark-defun-map "M" 'pp-macroexpand-expression))
|
|
|
|
;;; 99-misc.el ends here
|