[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Macros in dired - Is it possible?

From: zeek
Subject: Re: Macros in dired - Is it possible?
Date: Sat, 18 Jul 2009 10:19:03 -0700 (PDT)
User-agent: G2/1.0

> can you give description in terms of what you watn to do exactly?
> e.g.
> which files you want to process? are they all html files? files with
> certain line? etc?

First, thank you for replying.
Sorry for the confusion, simplified it too much. Let me try again

60% of all the files are just plain text files
40% are html files

I have 2 macros: one for plain text files and another for html files
a) The macro for the plain text files looks for certain individual
words, and then tries to delete the paragraph that contains that word
(actually, it just deletes the line that contains the words and the
line above and the line below it (as you astutely surmised).  I would
like it to delete paragraphs, but this is the best I could do.
b) The macro for the html files looks for the same certain words, and
then deletes everything between these two tags: <file> and </file>

Then, I manually save the file so that I can read the text and html
versions later on in the day.  Generally, for the text files, the size
gets reduced by about 20-50%.

Why am I doing this? Over the years I have learned that certain
individuals take for ever to get to the point, and that when these
individuals use certain words  or phrases, the entire paragraph
containing those words/phrases is just bla, bla, bla.  So the macro
just deletes them for me before I read them.
Do the paragraphs that get deleted contain information that I am
interested in knowing about?  Yes, but very rarely.  So far it has
never been a problem.

So I do the following for every file from these certain individuals:
Open the file in a buffer
Type C-u 0 M-x RET
Manually save the file.
Kill the buffer
Now, do the exact same thing for the next file, and the next, and the
next, etc

What would be nice is to just do this one time.  So I was thinking
would it be possible to mark all the text files in dired and run the
macro on all the marked files?

The macros run ok, but I have to manually save the file and manually
kill the buffer before moving on to the next file.  I could never get
the macros to save and the kill the buffer for me, so that is why I am
saving and killing the buffer manually.

Both macros (the one for the text files and the one for the html
files) are saved in Lisp code in my .emacs file.

> what do you want to do to each file? delete certain lines, then save?
> what text pattern does the line needs to match? etc.

For text files, delete every paragraph that contains those certain
words and save the file
For html files, delete everything between the two tags: <file> </file>
and save the file

Example of word searched for: "vacation"
Example of phrase searched for "when I was"
These are not the actual words/phrases that I search for, but does get
the point across. I search for 6 words and 1 phrase.

> kbd macros are typically one session use only. they are not meant to
> be edited, and they are pretty unreadable. They simply are record of
> keystrokes. In your case, of calling kbd macros on kbd macros, is
> probably much simpler having a elisp function.
Oh, I see, that is why you are asking for the pattern to match. Never
thought of a function.  Don't know how to do that yet. Not there yet
in the Emacs Lisp tutorial.

Snippet of html macro via M-x edit-named-kbd-macro
3*<C-home>              ;; beginning-of-buffer
C-s                     ;; isearch-forward
v                       ;; self-insert-command
a                       ;; self-insert-command
c                       ;; self-insert-command
a                       ;; self-insert-command
t                       ;; self-insert-command
i                       ;; self-insert-command
o                       ;; self-insert-command
n                       ;; self-insert-command
RET                     ;; org-return
C-c C-b                 ;; outline-backward-same-level
C-SPC                   ;; set-mark-command
C-c C-f                 ;; outline-forward-same-level
C-w                     ;; kill-region
C-d                     ;; delete-char
C-a                     ;; org-beginning-of-line


reply via email to

[Prev in Thread] Current Thread [Next in Thread]