From 997e583f84b3c711e95f9f8b2a7eba2567ee9e77 Mon Sep 17 00:00:00 2001 From: Vladislav Slobodenyuk Date: Mon, 2 Dec 2024 22:08:35 +0900 Subject: [PATCH] Add miscellaneous functions file --- .config.d/99-misc.el | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .config.d/99-misc.el diff --git a/.config.d/99-misc.el b/.config.d/99-misc.el new file mode 100644 index 0000000..fd3bbc8 --- /dev/null +++ b/.config.d/99-misc.el @@ -0,0 +1,35 @@ +;;; 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))) + +(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) + +;;; 99-misc.el ends here