0

I'm having some trouble coming up with regular expressions for variables paragraph-start and paragraph-separate to do what I want (to be defined shortly). I'm editing *.srt files (subtitles for school lectures) and trying to set my variables so that M - } and M - { take me up and back one block of text for editing. The file has the following format:

1
00:00:16,040 --> 00:00:23,130
Some text here that marks the beginning       <--
of a block.

2
00:00:23,390 --> 00:00:28,230
(Speaker): And some more                      <--

3
00:00:28,230 --> 00:00:32,350
text here that also marks the                 <--
beginning of another block. There
could be multiple sentences in here.

I want to set variables paragraph-start and paragraph-separate in such a way that M-{ and M-} (paragraph back and forward) take me between the beginning of the lines marked with <--.

I tried to set paragraph-separate to ".*-->.*" (since the arrow never appears in the subtitles text) and paragraph-start to match any after this line, but M-} always seems to place me on the timestamps line (the one including the -->), although I want to go to the line after it.

Any ideas what I'm doing wrong and how I can set the variables paragraph-start and paragraph-separate appropriately?

1 Answer 1

0

The following code will probably do what you want.

Note that it will change globally M-{ and M-}.

I would use an hydra for this (assuming that I would use also other functions during file editing).

(defun adl/srt-backward-paragraph ()
  (interactive)
  (backward-paragraph 2)
  (if (= (point) (point-min))
      (next-line 2)    
    (next-line 3)))

(defun adl/srt-forward-paragraph ()
  (interactive)
  (forward-paragraph)
  (while (= (char-after) 10) (next-line))
  (next-line 2))


(global-set-key (kbd "M-{") 'adl/srt-backward-paragraph)
(global-set-key (kbd "M-}") 'adl/srt-forward-paragraph)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.