Gnus development mailing list
 help / color / mirror / Atom feed
From: "François Pinard" <pinard@iro.umontreal.ca>
Subject: Editing (text/enriched) parts revisited
Date: 26 Apr 1999 10:50:47 -0400	[thread overview]
Message-ID: <oqk8uzv3js.fsf@titan.progiciels-bpi.ca> (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

             reply	other threads:[~1999-04-26 14:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-26 14:50 François Pinard [this message]
1999-04-26 15:14 ` Kai.Grossjohann

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=oqk8uzv3js.fsf@titan.progiciels-bpi.ca \
    --to=pinard@iro.umontreal.ca \
    /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.
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).