all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* message, can't find basic stuff [Elisp]
@ 2021-02-20  1:12 Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-20  9:23 ` Philip Kaludercic
  0 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-20  1:12 UTC (permalink / raw)
  To: help-gnu-emacs

I just answered a question on gmane.emacs.gnus.general but had
to write a lot more code than I thought.

Is there really no - argh, just read the code, the questions
are in the comments :)

(require 'message)

;; is there really no function like this already?
(defun message-set-header (hdr val)
  (interactive "sheader: \nsvalue: ")
  ;; check here if there _is_ such a header - how?
  ;; also a must-have, super-simple building-block from the holster
  ;; but can't find it either
  (message-position-on-field hdr)
  (message-beginning-of-line)
  (delete-region (point) (point-at-eol))
  (insert val) )
;; test: 
;; (message-set-header "Subject" "Lara loves YOU")

(defun message-transpose-headers (hdr1 hdr2)
  (interactive "sheader 1: \nsheader 2: ")
  (let ((v1 (message-field-value hdr1))
        (v2 (message-field-value hdr2)))
    (message-set-header hdr1 v2)
    (message-set-header hdr2 v1) ))
;; test:
;; (message-transpose-headers "To" "Subject")

https://dataswamp.org/~incal/emacs-init/gnus/message-incal.el

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: message, can't find basic stuff [Elisp]
  2021-02-20  1:12 message, can't find basic stuff [Elisp] Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-02-20  9:23 ` Philip Kaludercic
  2021-02-20 18:44   ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 5+ messages in thread
From: Philip Kaludercic @ 2021-02-20  9:23 UTC (permalink / raw)
  To: help-gnu-emacs

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

Emanuel Berg via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

> I just answered a question on gmane.emacs.gnus.general but had
> to write a lot more code than I thought.
>
> Is there really no - argh, just read the code, the questions
> are in the comments :)
>
> (require 'message)
>
> ;; is there really no function like this already?
> (defun message-set-header (hdr val)
>   (interactive "sheader: \nsvalue: ")
>   ;; check here if there _is_ such a header - how?
>   ;; also a must-have, super-simple building-block from the holster
>   ;; but can't find it either

Perhaps message-fetch-field? It returns the value or nil if not found.

>   (message-position-on-field hdr)
>   (message-beginning-of-line)
>   (delete-region (point) (point-at-eol))
>   (insert val) )
> ;; test: 
> ;; (message-set-header "Subject" "Lara loves YOU")

All I know of is message-add-header, but pass it an entire line, not a
header-value pair.

-- 
	Philip K.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 686 bytes --]

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

* Re: message, can't find basic stuff [Elisp]
  2021-02-20  9:23 ` Philip Kaludercic
@ 2021-02-20 18:44   ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-20 19:04     ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-20 18:44 UTC (permalink / raw)
  To: help-gnu-emacs

Philip Kaludercic wrote:

> Perhaps message-fetch-field? It returns the value or nil if
> not found.

Yes, but it returns nil for an unset header as well, e.g.
just "To:" with no value, that also returns nil. (Which makes
sense for that function.)

>>   (message-position-on-field hdr)
>>   (message-beginning-of-line)
>>   (delete-region (point) (point-at-eol))
>>   (insert val) )
>> ;; test: 
>> ;; (message-set-header "Subject" "Lara loves YOU")
>
> All I know of is message-add-header, but pass it an entire
> line, not a header-value pair.

Unbelievable all this basic stuff isn't there. Without it, how
is the software built up to begin with? It probably still
exists but with different names etc.

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: message, can't find basic stuff [Elisp]
  2021-02-20 18:44   ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-02-20 19:04     ` Emanuel Berg via Users list for the GNU Emacs text editor
  2021-02-21  4:50       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-20 19:04 UTC (permalink / raw)
  To: help-gnu-emacs

Better versions:

(defun message-set-header (hdr val)
  (interactive "sheader: \nsvalue: ")
  (message-position-on-field hdr)
  (message-beginning-of-header nil)
  (delete-region (point) (point-at-eol))
  (insert val) )
;; test:
;; (message-set-header "Subject" "Lara loves YOU")

(defun message-transpose-headers (hdr1 hdr2)
  (interactive "sheader 1: \nsheader 2: ")
  (save-excursion
    (let ((v1 (or (message-field-value hdr1) ""))
          (v2 (or (message-field-value hdr2) "")) )
      (message-set-header hdr1 v2)
      (message-set-header hdr2 v1) )))
;; test:
;; (message-transpose-headers "To" "Subject")

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

* Re: message, can't find basic stuff [Elisp]
  2021-02-20 19:04     ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-02-21  4:50       ` Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-02-21  4:50 UTC (permalink / raw)
  To: help-gnu-emacs

A yet better version, with a little help from my friends at
gmane.emacs.gnus.general

No need for that other function - I guess that's why it isn't
in Emacs LOL

(defun message-transpose-headers (hdr1 hdr2)
  (interactive "sheader 1: \nsheader 2: ")
  (save-excursion
    (message-position-on-field hdr1)
    (message-position-on-field hdr2)
    (let ((v1 (or (message-field-value hdr1) ""))
          (v2 (or (message-field-value hdr2) "")) )
      (message-replace-header hdr1 v2 "From" t)
      (message-replace-header hdr2 v1 "To"   t)) ))
;; test:
;; (message-transpose-headers "To" "Subject")

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




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

end of thread, other threads:[~2021-02-21  4:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-20  1:12 message, can't find basic stuff [Elisp] Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-20  9:23 ` Philip Kaludercic
2021-02-20 18:44   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-20 19:04     ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-02-21  4:50       ` Emanuel Berg via Users list for the GNU Emacs text editor

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.