J'aimerais fixer le coding system que j'ai sous forme de chaîne (e.g.
"iso-8859-1", "UTF-8", etc., la chaîne venant de la valeur de charset
dans un mail). C'est pour utiliser avec modify-coding-system-alist où
le 2e argument est un symbole de fonction; il faut donc que je renvoie
un symbole correspondant au coding system.
J'ai vu que po-compat.el utilise une liste po-content-type-charset-alist
qui donne diverses correspondances chaîne -> symbole. Idem pour
latexenc.el (latex-inputenc-coding-alist). N'existe-t-il pas une
telle liste en standard?
(defun mutt-find-file-coding-system (arg-list)
"\
Determine the coding system of a mail file. Use the current locale if the
file doesn't declare a charset (in practice, when composing a mail message
instead of editing one). This is a heuristic."
(if (eq (car arg-list) 'insert-file-contents)
(let ((case-fold-search t))
(save-excursion
(goto-char (point-min))
(cond
((looking-at "^From:") ;; Composed mail (new mail or reply).
locale-coding-system)
((and (search-forward-regexp
"^\\(.+\n\\)*Content-Transfer-Encoding: 8bit"
nil t)
(progn
(goto-char (point-min))
(search-forward-regexp
"^\\(.+\n\\)*Content-Type:.*charset=\"?\\([-0-9a-z]*\\)"
nil t)))
(message (match-string 2)))
(t 'undecided-unix))))
'undecided-unix)
)
le 2e argument est un symbole de fonction; il faut donc que je renvoie un symbole correspondant au coding system.
(eq (intern "foo") 'foo) renvoie 't.
Ça aide ?
-- Matthieu
Vincent Lefevre
Dans l'article , Matthieu Moy écrit:
(eq (intern "foo") 'foo) renvoie 't.
Ça aide ?
Merci. En fait les deux fonctions que je citais l'utilisent dans certains cas, mais je n'avais pas fait attention, comme je ne connaissais pas... Maintenant ça fonctionne bien:
(defun mutt-find-file-coding-system (arg-list) " Determine the coding system of a mail file. Use the current locale if the file doesn't declare a charset (in practice, when composing a mail message instead of editing one). This is a heuristic." (if (eq (car arg-list) 'insert-file-contents) (let ((case-fold-search t)) (save-excursion (goto-char (point-min)) (cond ((looking-at "^From:") ;; Composed mail (new mail or reply). locale-coding-system) ((and (search-forward-regexp "^(.+n)*Content-Transfer-Encoding: 8bit" nil t) (progn (goto-char (point-min)) (search-forward-regexp "^(.+n)*Content-Type:.*charset="?([-0-9a-z]*)" nil t))) (let ((charset (intern (downcase (match-string 2))))) (if (memq charset (coding-system-list)) charset 'undecided-unix))) (t 'undecided-unix)))) 'undecided-unix) )
Dans l'article <vpqhct1gsjr.fsf@olympe.imag.fr>,
Matthieu Moy <MatthieuNOSPAM.Moy@imag.fr.invalid> écrit:
(eq (intern "foo") 'foo) renvoie 't.
Ça aide ?
Merci. En fait les deux fonctions que je citais l'utilisent dans
certains cas, mais je n'avais pas fait attention, comme je ne
connaissais pas... Maintenant ça fonctionne bien:
(defun mutt-find-file-coding-system (arg-list)
"
Determine the coding system of a mail file. Use the current locale if the
file doesn't declare a charset (in practice, when composing a mail message
instead of editing one). This is a heuristic."
(if (eq (car arg-list) 'insert-file-contents)
(let ((case-fold-search t))
(save-excursion
(goto-char (point-min))
(cond
((looking-at "^From:") ;; Composed mail (new mail or reply).
locale-coding-system)
((and (search-forward-regexp
"^\(.+n\)*Content-Transfer-Encoding: 8bit"
nil t)
(progn
(goto-char (point-min))
(search-forward-regexp
"^\(.+n\)*Content-Type:.*charset="?\([-0-9a-z]*\)"
nil t)))
(let ((charset (intern (downcase (match-string 2)))))
(if (memq charset (coding-system-list))
charset
'undecided-unix)))
(t 'undecided-unix))))
'undecided-unix)
)
Merci. En fait les deux fonctions que je citais l'utilisent dans certains cas, mais je n'avais pas fait attention, comme je ne connaissais pas... Maintenant ça fonctionne bien:
(defun mutt-find-file-coding-system (arg-list) " Determine the coding system of a mail file. Use the current locale if the file doesn't declare a charset (in practice, when composing a mail message instead of editing one). This is a heuristic." (if (eq (car arg-list) 'insert-file-contents) (let ((case-fold-search t)) (save-excursion (goto-char (point-min)) (cond ((looking-at "^From:") ;; Composed mail (new mail or reply). locale-coding-system) ((and (search-forward-regexp "^(.+n)*Content-Transfer-Encoding: 8bit" nil t) (progn (goto-char (point-min)) (search-forward-regexp "^(.+n)*Content-Type:.*charset="?([-0-9a-z]*)" nil t))) (let ((charset (intern (downcase (match-string 2))))) (if (memq charset (coding-system-list)) charset 'undecided-unix))) (t 'undecided-unix)))) 'undecided-unix) )