diff options
author | Mountain Man <43313373+MountainMan1312@users.noreply.github.com> | 2023-11-29 19:56:06 -0500 |
---|---|---|
committer | Mountain Man <43313373+MountainMan1312@users.noreply.github.com> | 2023-11-29 19:56:06 -0500 |
commit | 7aa249011da4a10afab08ec143415dae883a8031 (patch) | |
tree | 630e802e2bdf49b71535ac3b5f0d12083ee88267 | |
parent | Add keybind for pdf-outline (diff) | |
download | mmosmacs-7aa249011da4a10afab08ec143415dae883a8031.tar.gz mmosmacs-7aa249011da4a10afab08ec143415dae883a8031.tar.bz2 mmosmacs-7aa249011da4a10afab08ec143415dae883a8031.zip |
Rename org-mode buffers to value of `#+TITLE:`
-rw-r--r-- | init.el | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -1006,6 +1006,31 @@ | |||
1006 | ("C-c n l t" . org-toggle-link-display) | 1006 | ("C-c n l t" . org-toggle-link-display) |
1007 | ("C-c t" . org-agenda-todo)) | 1007 | ("C-c t" . org-agenda-todo)) |
1008 | 1008 | ||
1009 | ;; Set buffer name to #+TITLE | ||
1010 | ;; Credit to SE user "Tobias" | ||
1011 | (defun mm/org-buffer-name-to-title (&optional end) | ||
1012 | "Rename buffer to value of #+TITLE:. | ||
1013 | if END if non-nil, search for #+TITLE: at `point' and | ||
1014 | delimit it to END. Start an unlimited search at | ||
1015 | `point-min' otherwise." | ||
1016 | (interactive) | ||
1017 | (let ((beg (or (and end (point)) | ||
1018 | (point-min)))) | ||
1019 | (save-excursion | ||
1020 | (when end | ||
1021 | (goto-char end) | ||
1022 | (setq end (line-end-position))) | ||
1023 | (goto-char beg) | ||
1024 | (when (re-search-forward "^[[:space:]]*#\\+TITLE:[[:space:]]*\\(.*?\\)[[:space:]]*$" end t) | ||
1025 | (rename-buffer (match-string 1))))) | ||
1026 | nil) | ||
1027 | |||
1028 | (defun mm/org-buffer-name-to-title-config () | ||
1029 | "Configure Org to rename buffer to value of #+TITLE:." | ||
1030 | (font-lock-add-keywords nil '(mm/org-buffer-name-to-title))) | ||
1031 | |||
1032 | (add-hook 'org-mode-hook #'mm/org-buffer-name-to-title-config) | ||
1033 | |||
1009 | ;; Make org heading bullets look nicer | 1034 | ;; Make org heading bullets look nicer |
1010 | (use-package org-bullets | 1035 | (use-package org-bullets |
1011 | :straight t | 1036 | :straight t |