From: Arthur Miller <arthur.miller@live.com>
To: emacs-devel@gnu.org
Subject: Font-lock in a buffer inserted in Dired buffer?
Date: Thu, 26 Nov 2020 17:21:09 +0100 [thread overview]
Message-ID: <AM0PR06MB65774E13128F6E81234448D696F90@AM0PR06MB6577.eurprd06.prod.outlook.com> (raw)
[-- Attachment #1: dired-auto-readme.el --]
[-- Type: text/plain, Size: 3022 bytes --]
;;; dired-auto-readme.el --- -*- lexical-binding: t; -*-
;; Copyright (C) 2020 Arthur Miller
;; Author: Arthur Miller <arthur.miller@live.com>
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(defvar dired-auto-readme-files '("README"
"README.md"
"README.org"
"README.txt")
"List of README file names to automatically display. First file in the
directory matching the list is used. ")
(defun dired-auto-readme--insert ()
"Insert README file in the current buffer. "
(setq inhibit-read-only t)
(catch 'break
(dolist (file dired-auto-readme-files)
(when (file-exists-p file)
(save-excursion
(let ((readme-text))
(with-current-buffer (get-buffer-create file)
(insert-file-contents file)
(font-lock-ensure)
(indent-region (point-min) (point-max))
(setq readme-text (buffer-substring (point-min) (point-max)))
;;(kill-buffer)
)
(goto-char (point-max))
(make-variable-buffer-local 'dired-auto-readme--start-point)
(setq dired-auto-readme--start-point (point))
(insert readme-text))
(setq dired-auto-readme--inserted t)
(setq inhibit-read-only nil)
(throw 'break t))))))
(defun dired-auto-readme--remove ()
(setq inhibit-read-only t)
(save-excursion
(goto-char dired-auto-readme--start-point)
(delete-region (point) (point-max)))
(setq dired-auto-readme--inserted nil)
(setq inhibit-read-only t))
;;;###autoload
(define-minor-mode dired-auto-readme-mode
"Dired minor mode to preview README in current directory."
:global nil :lighter " README"
(when (derived-mode-p 'dired-mode)
(make-variable-buffer-local 'dired-auto-readme--inserted)
(cond (dired-auto-readme-mode
(unless dired-auto-readme--inserted
(dired-auto-readme--insert))
;; hook run by `dired-revert'
(add-hook 'dired-after-readin-hook
#'dired-auto-readme--insert nil t))
(t
(when dired-auto-readme--inserted
(dired-auto-readme--remove))
(remove-hook 'dired-after-readin-hook
#'dired-auto-readme--insert t)))))
(provide 'dired-auto-readme)
;;; dired-auto-readme.el ends here
[-- Attachment #2: Type: text/plain, Size: 504 bytes --]
I am opening a file in it's own buffer, and hoping trying to get Emacs
to font-lock it. I am not sure if font-lock will do it's thing when
buffer is loaded or when it is displayed so I am calling
(font-lock-ensure) to get it to (hopefully) kick-in. I see also dired is
trying to font-lock inserted text.
1. what do I need to call to make it to font-lock
2. how do I tell Dired to give crap to font-lock the text after the
insertion? Can I disable just a region from font-lock?
Thanks for any help!
reply other threads:[~2020-11-26 16:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AM0PR06MB65774E13128F6E81234448D696F90@AM0PR06MB6577.eurprd06.prod.outlook.com \
--to=arthur.miller@live.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.