help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems fontifying after narrowing into a different mode


From: Denis Bueno
Subject: Problems fontifying after narrowing into a different mode
Date: Wed, 14 Dec 2011 23:57:25 -0700

I edit CWEB source [1] sometimes and I'd like to make it more
convenient. Specifically, I want to be able to narrow to a region of a
given buffer, switch major modes, and fortify the (narrowed) buffer.
For example, I want to choose a region, switch to c-mode, and edit C
code. The definitions and bindings help me do this.

The short story: text outside the narrowed region is affecting the
fontifying so my C code doesn't fontify properly. Can anyone suggest
code for doing what I want? Read on for the way to reproduce what I'm
seeing.

For example, given the following CWEB file in a buffer (just the stuff
in between the File/End File things):

|== File ==
@* Intro. See the single quote: '

@<External ty...@>=
typedef struct hitable
{
  int k;
} hitable;
|== End File ==

Run emacs -Q, load my definitions below, select the typedef, and hit
'C-x n c' to narrow to the code and switch to the code mode. In my
emacs---GNU Emacs 23.3.1 (x86_64-apple-darwin, NS
apple-appkit-1038.36) of 2011-12-13 on bob.porkrind.org---it
highlights the entire code as if it were a C string. If the single
quote (which is outside the narrowed buffer) is removed, the code
fontifies properly.

;;; useful for cweb mode. narrows to a region then sets a mode.
(defvar narrow-to-code-region-mode 'c-mode)
(defvar narrow-to-doc-region-mode 'TeX-mode) ;; from AUCTeX
(defvar widen-mode 'text-mode)

(defun narrow-to-code-region-and-change-mode (beg end)
  "Change to `narrow-to-code-region-mode'."
  (interactive (list (point) (mark)))
  (narrow-to-region beg end)
  (call-interactively narrow-to-code-region-mode))
(global-set-key (kbd "C-x n c") 'narrow-to-code-region-and-change-mode)
(defun narrow-to-doc-region-and-change-mode (beg end)
  "Change to `narrow-to-doc-region-mode'."
  (interactive (list (point) (mark)))
  (narrow-to-region beg end)
  (call-interactively narrow-to-doc-region-mode))
(global-set-key (kbd "C-x n d") 'narrow-to-doc-region-and-change-mode)

(defun widen-and-change-mode ()
  "Change to `widen-mode'."
  (interactive)
  (widen)
  (call-interactively widen-mode))
(global-set-key (kbd "C-x n r") 'widen-and-change-mode)

Can anyone suggest a fix?

[1] http://www-cs-staff.stanford.edu/~uno/cweb.html

-- 
                              Denis



reply via email to

[Prev in Thread] Current Thread [Next in Thread]