all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Problems fontifying after narrowing into a different mode
@ 2011-12-15  6:57 Denis Bueno
  0 siblings, 0 replies; only message in thread
From: Denis Bueno @ 2011-12-15  6:57 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-12-15  6:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-15  6:57 Problems fontifying after narrowing into a different mode Denis Bueno

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.