all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Wrap around and comment function
@ 2005-11-29  3:56 Harry Putnam
  2005-11-29  4:21 ` Chong Yidong
  0 siblings, 1 reply; 4+ messages in thread
From: Harry Putnam @ 2005-11-29  3:56 UTC (permalink / raw)


I'm hoping there is something that does what I describe below
somewhere in a repository.  Or at least something that is close enough
to allow a (seriously) lisp challenged emacs user to get this from it.

I'd like a function that acts on region by inserting a line like this
above region:

# [HP DATE - NOTE: <Here I get queried for a few words then <RET>>
# Then region is commented  
# with whatever  comment style 
# is dictated by mode.
# Finally insert a line below region like:
# ==*  END HP NOTE *== ]

If that isn't confusing enough I'll try to spell it out.

Write a commented line with some static info:
   [HP DATE - NOTE:
   (Where date is MMDDYY_HHMMSS)
Then the function queries me for a few words of my choice followed by
<RET>  Which is also written to the same line.

When I hit <RET> the function comments the region with whatever
comment is dictated by mode, and inserts a closing line:

   # ==*  END HP NOTE *== ]

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

* Re: Wrap around and comment function
  2005-11-29  3:56 Wrap around and comment function Harry Putnam
@ 2005-11-29  4:21 ` Chong Yidong
  2005-11-30 13:55   ` Harry Putnam
  2005-11-30 14:36   ` Harry Putnam
  0 siblings, 2 replies; 4+ messages in thread
From: Chong Yidong @ 2005-11-29  4:21 UTC (permalink / raw)


Harry Putnam <reader@newsguy.com> writes:

> I'm hoping there is something that does what I describe below
> somewhere in a repository.  Or at least something that is close enough
> to allow a (seriously) lisp challenged emacs user to get this from it.
>
> I'd like a function that acts on region by inserting a line like this
> above region:
>
> # [HP DATE - NOTE: <Here I get queried for a few words then <RET>>
> # Then region is commented  
> # with whatever  comment style 
> # is dictated by mode.
> # Finally insert a line below region like:
> # ==*  END HP NOTE *== ]

Probably something like this:

(defun foo (beg end string)
  (interactive "*r\nsEnter a few words: ")
  (let ((fin (copy-marker end)))
    (goto-char beg)
    (insert "[HP DATE - NOTE: " string "\n")
    (goto-char (marker-position fin))
    (set-marker fin nil)
    (insert "\n==*  END HP NOTE *== ]\n")
    (comment-region beg (point))))

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

* Re: Wrap around and comment function
  2005-11-29  4:21 ` Chong Yidong
@ 2005-11-30 13:55   ` Harry Putnam
  2005-11-30 14:36   ` Harry Putnam
  1 sibling, 0 replies; 4+ messages in thread
From: Harry Putnam @ 2005-11-30 13:55 UTC (permalink / raw)


Chong Yidong <cyd@stupidchicken.com> writes:


[...]

> Probably something like this:
>
> (defun foo (beg end string)
>   (interactive "*r\nsEnter a few words: ")
>   (let ((fin (copy-marker end)))
>     (goto-char beg)
>     (insert "[HP DATE - NOTE: " string "\n")
>     (goto-char (marker-position fin))
>     (set-marker fin nil)
>     (insert "\n==*  END HP NOTE *== ]\n")
>     (comment-region beg (point))))

Yup, that is pretty slick.  Looks like I just need to save a
formatted date in a var and use it at:
  [HP MYVAR - NOTE:

Thank you.  Nice function and surprisingly brief.

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

* Re: Wrap around and comment function
  2005-11-29  4:21 ` Chong Yidong
  2005-11-30 13:55   ` Harry Putnam
@ 2005-11-30 14:36   ` Harry Putnam
  1 sibling, 0 replies; 4+ messages in thread
From: Harry Putnam @ 2005-11-30 14:36 UTC (permalink / raw)


Chong Yidong <cyd@stupidchicken.com> writes:

> Probably something like this:
>
> (defun foo (beg end string)
>   (interactive "*r\nsEnter a few words: ")
>   (let ((fin (copy-marker end)))
>     (goto-char beg)
>     (insert "[HP DATE - NOTE: " string "\n")
>     (goto-char (marker-position fin))
>     (set-marker fin nil)
>     (insert "\n==*  END HP NOTE *== ]\n")
>     (comment-region beg (point))))


I'm liking this more and more... I figured out how to include the date
and fixed up for actual use.  I really like this and will use it a lot
Thanks:

;; From: Chong Yidong <cyd@stupidchicken.com>
;; Subject: Re: Wrap around and comment function
;; Newsgroups: gmane.emacs.help
;; Date: Mon, 28 Nov 2005 23:21:44 -0500
;; Message-ID: <87acfo6q3r.fsf@stupidchicken.com>

(defun GrabAndSurround (beg end string)
  (interactive "*r\nsEnter a few keywords: ")
  (let ((fin (copy-marker end)))
    (goto-char beg)
    (insert (format-time-string "HP %m%d%y_%M%H%S NOTE: ") string "\n")
;;    (insert "[HP DATE - NOTE: " string "\n")
    (goto-char (marker-position fin))
    (set-marker fin nil)
    (insert "     ==*  END HP NOTE *== ]\n")
    (comment-region beg (point))))


If I wanted to save the date into a variable and put the variable into
the string instead of generating a formatted date there.  Like if I
wanted to use the same current date in seveal places in my code for
example, how would I do that?

Also maybe you can point me in the right direction using similar code,
not commenting the region, still inserting pre string and post
string but then appending it to an existing file, and be queried for
file name.

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

end of thread, other threads:[~2005-11-30 14:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-29  3:56 Wrap around and comment function Harry Putnam
2005-11-29  4:21 ` Chong Yidong
2005-11-30 13:55   ` Harry Putnam
2005-11-30 14:36   ` Harry Putnam

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.