Input and desired output
Original code Commented out code: C %% MODULE %% module_name C~ CPR C ## MODULE ## module_name lines of code C~ CPR lines of code lines of code C~ CPR lines of code ..... C~ CPR ..... ..... C~ CPR ..... ..... C~ CPR .... .... C~ CPR .... .... C~ CPR .... C %% END MODULE %% module_name C~ CPR C ## END MODULE ## module_name
Steps:
- The cursor (point) is usually somewhere in between the
C %% MODULE %%andC %% END MODULE %% - Select the lines between
C %% MODULE %%andC %% END MODULE %%andreplace-string%%with## - The
C-x C-xto make the repeat the last selection and runstring-insert-rectangleand insert the comment textC~ CPR-
My Function (I'm new to elisp, bear with my terrible code)
(defun comment-pdtn() (interactive) (set-buffer (buffer-name)) (search-backward "C %% MODULE %%") (set-mark (- (point) 14)) ;; 14 is the # of char in C %% MODULE %% (search-forward "C %% END MODULE %%") (message "begin at %s and ends at %s" ;; Want to ensure that region selection happened (region-beginning) (region-end)) (string-insert-rectangle "C~ CPR ")) ;; This isn't working (comment-pdtn) I'm yet to add the functionality for replace-string yet. How to implement string-insert-rectanglein Elisp? I want to write something like this,
- With region ( string-insert-rectangle "C~ CPR ")
- With region ( replace-string "%%" "##")
I could do this with macro and save the macro and do away with it, but I want to learn elisp that is the reason behind this question.
M-;in conjunction with the config(setq comment-start "C~ CPR " comment-start-skip "C~ CPR +" comment-use-syntax nil)which could be set in the mode hook for whatever mode this is.M-;but didn't know how. From where can I learn thisC-h i g (emacs)Options for Commentsand the docstrings for the variables in question.