bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#46621: Copy line


From: Gregory Heytings
Subject: bug#46621: Copy line
Date: Mon, 22 Feb 2021 17:04:02 +0000



Bottom line, if we want to consider this command, we should somehow come up with the relevant use cases, and then weigh them against the added complexity and maintenance costs. I therefore urge people who think they know these details to please speak up and contribute to this discussion.


My 2 cents: a typical case where this could be useful is:

switch (foobar) {
case long_enum_value_name_a: printf ("a"); break;
case long_enum_value_name_b: printf ("b"); break;
case long_enum_value_name_c: printf ("c"); break;
case long_enum_value_name_d: printf ("d"); break;
case long_enum_value_name_e: printf ("e"); break;
case long_enum_value_name_f: printf ("f"); break;
case long_enum_value_name_g: printf ("g"); break;
case long_enum_value_name_h: printf ("h"); break;
case long_enum_value_name_i: printf ("i"); break;
default: printf ("?"); break;
}

Another typical case:

import java.util.Set;
import java.util.TreeSet;
import java.util.HashSet;
import java.util.LinkedHashSet;

I agree with Richard that this can be done with C-a C-k C-k C-y..., which is what I've been using in such cases, but that doesn't mean that the proposed command wouldn't be welcome. I agree with Juri that Richard's solution "pollutes" the kill-ring with something that the user actually did not want to kill. I would suggest the following (based on Juri's code):

(defun duplicate-line (&optional arg)
  (interactive "p")
  (save-mark-and-excursion
    (dotimes (_ arg)
      (forward-line 1)
      (insert "\n")
      (forward-line -1)
      (copy-from-above-command))))
(global-set-key (kbd "C-x r z") 'duplicate-line)

reply via email to

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