Search code examples
emacselisp

handle lines in region or not


I have N lines with code like this:

let aafdafa
let bfaf
let cb

I want translate this code to this:

let aafdafa = aafdafa.len();
let bfaf = bfaf.len();
let cb = cb.len();

replace-regexp not work with selection, how should I solve this task in emacs?


Solution

  • This would be a task for an Emacs Macro: https://www.emacswiki.org/emacs/KeyboardMacros

    Macros are built-in powerful features to record and repeat key strokes. You could:

    1. Go to the beginning of the line
    2. Jump one word (to the var) and yank it
    3. Add an =
    4. Paste the var
    5. Add .len();

    And then repeat n times.