Gnus development mailing list
 help / color / mirror / Atom feed
* Editing (text/enriched) parts revisited
@ 1999-04-26 14:50 François Pinard
  1999-04-26 15:14 ` Kai.Grossjohann
  0 siblings, 1 reply; 2+ messages in thread
From: François Pinard @ 1999-04-26 14:50 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 1691 bytes --]

Hi, people.

Here is below a slightly adjusted version of the code we have for editing
text/enriched parts.  `M-m p' works for me now, and I changed its default
to "text/plain".  My guess is that most parts we want to edit with special
modes are most probably text/plain in their intent.

I got a slight problem, maybe some of you have a solution for it?  If I use
`M-m p' followed by `M-x c-mode' to edit some C code right in a message, the
`C-c C-c' local keymap stops being available to end editing that part, as
`C-c C-c' means `comment-region' in C mode.  I'm no big Emacs LISP expert,
maybe someone might explain me how I could override `C-c C-c' nevertheless?
Or else, maybe we might choose another binding?

Another thing that could be fun, yet I did not explore it, would be the
ability to edit some C code with font-lock nice coloring, and then have
the result presented with enriched features in the message.  So, being able
to share right in a message the fruit-saladish aspect of my editing buffer.

I also wonder if <!#part> and <!/#part> should not receive special
automatic protection while get out of an indirect buffer, so to not
create overall invalid MML.  There is danger of overkill by trying to do
too much at inappropriate places, while there also is a need about being
able to easily quote MML without bothering about the quoting mechanism.
(I hope I did it correctly in this paragraph :-).

For example, I could not directly send the following code in-line: it raised
errors like:

   Scan error: "Containing expression ends prematurely", 2686, 2687

at `C-c C-c' time.  I would rather have done it in a more simple way.
These things should be plain easy to do...


[-- Attachment #2: snippet --]
[-- Type: application/octet-stream, Size: 3892 bytes --]

;;; Start of editing parts.

;; Editing parts generics.

(defvar message-edit-part-counter 0
  "Counter so all indirect buffers for editing MML parts are different.")

(defvar fp-mml-edit-part-map nil
  "Keymap while editing an MML part in an indirect buffer.")
(unless fp-mml-edit-part-map
  (setq fp-mml-edit-part-map (make-sparse-keymap))
  (define-key fp-mml-edit-part-map "\C-c\C-c" 'fp-mml-stop-edit-part))

(defun fp-mml-start-edit-part ()
  "Setup an indirect buffer to edit current or preceding MML part."
  (interactive)
  (let (begin-of-contents end-of-contents type)
    (save-excursion
      (let (start-tag)
	(unless (search-backward "<#part" nil t)
	  (error "Not within or after an MML part"))
	(setq start-tag (point))
	(unless (search-forward ">" nil)
	  (error "Unterminated MML part tag"))
	(setq begin-of-contents (point))
	(unless (re-search-backward "type=\"\\([a-z]+/[a-z]+\\)\"" start-tag t)
	  (error "No type/subtype in MML part tag"))
	(setq type (match-string 1))
	(goto-char begin-of-contents)
	(unless (search-forward "<#/part>" nil t)
	  (error "Unterminated MML part"))
	(setq end-of-contents (match-beginning 0))))
    (let ((name (format "*edit part <%d>*" (incf message-edit-part-counter)))
	  (start-action (intern-soft (concat "fp-mml-" type "-start-edit")))
	  (stop-action (intern-soft (concat "fp-mml-" type "-stop-edit"))))
      (switch-to-buffer (make-indirect-buffer (current-buffer) name))
      (narrow-to-region begin-of-contents end-of-contents)
      (when stop-action
	(make-local-variable 'mml-stop-edit-part-hook)
	(add-hook 'mml-stop-edit-part-hook stop-action))
      (when start-action
	(apply start-action nil))
      (use-local-map fp-mml-edit-part-map)
      (message "Type `C-c C-c' once done"))))

(defun fp-mml-stop-edit-part ()
  "Get rid of the current indirect buffer for editing an MML part."
  (interactive)
  (run-hooks 'mml-stop-edit-part-hook)
  (kill-buffer (current-buffer)))

(autoload 'mml-minibuffer-read-type "mml")

(defun fp-mml-edit-new-part (type)
  "Make a new MIME part and select an indirect buffer for editing its contents.
TYPE is a string giving the MIME type and subtype, separated by a slash.
The buffer starts empty and is narrowed within the new MML construct."
  (interactive (list (mml-minibuffer-read-type nil "text/plain")))
  (insert "<#part type=\"" type "\" disposition=inline>")
  (insert "<#/part>\n")
  (fp-mml-start-edit-part))

(unless (fboundp 'buffer-indirect-children)
  (defun buffer-indirect-children (main-buffer)
    (and (bufferp main-buffer)
	 (let ((buffers (buffer-list))
	       result)
	   (while buffers
	     (let ((buffer (pop buffers)))
	       (when (eq (buffer-base-buffer buffer) main-buffer)
		 (push buffer result))))
	   result))))

(defun fp-mml-stop-edit-all-parts ()
  (let ((buffers (buffer-indirect-children (current-buffer))))
    (save-excursion
      (while buffers
	(set-buffer (pop buffers))
	(fp-mml-stop-edit-part)))))
(add-hook 'message-send-hook 'fp-mml-stop-edit-all-parts)

;; Editing text/enriched parts.

(defun fp-mml-edit-new-text/enriched-part ()
  (interactive)
  (fp-mml-edit-new-part "text/enriched"))

(defun fp-mml-text/enriched-start-edit ()
  (format-decode-region (point-min) (point-max) 'text/enriched)
  (enriched-mode 1))

(defun fp-mml-text/enriched-stop-edit ()
  (format-encode-region (point-min) (point-max) 'text/enriched)
  (goto-char (point-min))
  (forward-line 3)
  (delete-region (point-min) (point)))

;; Editing parts keymap.

(eval-after-load "mml"
  '(progn
     ;; FIXME: the \M-m is required?  "mml.el" does not use it, how comes?
     (define-key mml-mode-map "\M-me" 'fp-mml-start-edit-part)
     (define-key mml-mode-map "\M-mp" 'fp-mml-edit-new-part)
     (define-key mml-mode-map "\M-mr" 'fp-mml-edit-new-text/enriched-part)
     (define-key mml-mode-map "\M-mx" 'mml-attach-externel)))

;;; End of editing parts.

[-- Attachment #3: Type: text/plain, Size: 156 bytes --]


--
François Pinard                            mailto:pinard@iro.umontreal.ca
Join the free Translation Project!    http://www.iro.umontreal.ca/~pinard

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Editing (text/enriched) parts revisited
  1999-04-26 14:50 Editing (text/enriched) parts revisited François Pinard
@ 1999-04-26 15:14 ` Kai.Grossjohann
  0 siblings, 0 replies; 2+ messages in thread
From: Kai.Grossjohann @ 1999-04-26 15:14 UTC (permalink / raw)


François Pinard <pinard@iro.umontreal.ca> writes:

  > I got a slight problem, maybe some of you have a solution for it?
  > If I use `M-m p' followed by `M-x c-mode' to edit some C code
  > right in a message, the `C-c C-c' local keymap stops being
  > available to end editing that part, as `C-c C-c' means
  > `comment-region' in C mode.  I'm no big Emacs LISP expert, maybe
  > someone might explain me how I could override `C-c C-c'
  > nevertheless?  Or else, maybe we might choose another binding?

The Emacs server (see the emacsclient program) uses C-x #, and since
we can probably assume that the server-edit binding is not needed in
buffers created by M-m p...

A way to override the binding would the as follows: In M-m p, you ask
for a major mode to use.  You then execute the major mode function.
After that, you make a copy of the current local keymap and tell the
current buffer to use that copy as the local keymap.  Since this is a
unique Lisp object, you can redefine the C-c C-c binding without
clobbering the normal c-mode-map (say).

kai
-- 
Abort this operation?   [Abort]  [Cancel]


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-04-26 15:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-26 14:50 Editing (text/enriched) parts revisited François Pinard
1999-04-26 15:14 ` Kai.Grossjohann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).