The following code renames the buffer to the value of #+TITLE:
when you open the Org file. This is the most simple version. It does not update the buffer name when you add or change the title. But in that case you can call org+-buffer-name-to-title
directly if you really need it.
(defun org+-buffer-name-to-title ()
"Rename buffer to value of #+TITLE:."
(interactive)
(save-excursion
(goto-char (point-min))
(when (re-search-forward "^[[:space:]]*#\\+TITLE:[[:space:]]*\\(.*?\\)[[:space:]]*$" nil t)
(rename-buffer (match-string 1)))))
(add-hook 'org-mode-hook #'org+-buffer-name-to-title)
An enhanced version that exploits font lock to update the buffer name as you input the value of #+TITLE:
:
(defun org+-buffer-name-to-title (&optional end)
"Rename buffer to value of #+TITLE:.
If END is 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 org+-buffer-name-to-title-config ()
"Configure Org to rename buffer to value of #+TITLE:."
(font-lock-add-keywords nil '(org+-buffer-name-to-title)))
(add-hook 'org-mode-hook #'org+-buffer-name-to-title-config)