From 7aa249011da4a10afab08ec143415dae883a8031 Mon Sep 17 00:00:00 2001 From: Mountain Man <43313373+MountainMan1312@users.noreply.github.com> Date: Wed, 29 Nov 2023 19:56:06 -0500 Subject: Rename org-mode buffers to value of `#+TITLE:` --- init.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'init.el') diff --git a/init.el b/init.el index 94ace02..d4ec9c6 100644 --- a/init.el +++ b/init.el @@ -1006,6 +1006,31 @@ ("C-c n l t" . org-toggle-link-display) ("C-c t" . org-agenda-todo)) +;; Set buffer name to #+TITLE +;; Credit to SE user "Tobias" +(defun mm/org-buffer-name-to-title (&optional end) + "Rename buffer to value of #+TITLE:. +if END if non-nil, search for #+TITLE: at `point' and +delimit it to END. Start an unlimited search at +`point-min' otherwise." + (interactive) + (let ((beg (or (and end (point)) + (point-min)))) + (save-excursion + (when end + (goto-char end) + (setq end (line-end-position))) + (goto-char beg) + (when (re-search-forward "^[[:space:]]*#\\+TITLE:[[:space:]]*\\(.*?\\)[[:space:]]*$" end t) + (rename-buffer (match-string 1))))) + nil) + +(defun mm/org-buffer-name-to-title-config () + "Configure Org to rename buffer to value of #+TITLE:." + (font-lock-add-keywords nil '(mm/org-buffer-name-to-title))) + +(add-hook 'org-mode-hook #'mm/org-buffer-name-to-title-config) + ;; Make org heading bullets look nicer (use-package org-bullets :straight t -- cgit v1.2.3