Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crux-duplicate<-and-comment>-current-line-or-region using regions blends lines #84

Closed
Walheimat opened this issue Sep 8, 2021 · 2 comments · Fixed by #96
Closed

crux-duplicate<-and-comment>-current-line-or-region using regions blends lines #84

Walheimat opened this issue Sep 8, 2021 · 2 comments · Fixed by #96

Comments

@Walheimat
Copy link

Expected behavior

Given a region containing the following lines,

(message "the crux of the matter")
(message "hello from the magic tavern")

crux-duplicate-current-line-or-region yields:

(message "the crux of the matter")
(message "hello from the magic tavern")
(message "the crux of the matter")
(message "hello from the magic tavern")

Using crux-duplicate-and-comment-current-line-or-region yields:

;; (message "the crux of the matter")
;; (message "hello from the magic tavern")
(message "the crux of the matter")
(message "hello from the magic tavern")

Actual behavior

Using crux-duplicate-current-line-or-region I get:

(message "the crux of the matter")
(message "hello from the magic tavern")(message "the crux of the matter")
(message "hello from the magic tavern")

Using crux-duplicate-and-comment-current-line-or-region I get:

;; (message "the crux of the matter")
;; (message "hello from the magic tavern")(message "the crux of the matter")
(message "hello from the magic tavern")

Steps to reproduce the problem

Call the mentioned commands with active region.

Commenting out these line makes the commands work as before:

(unless (use-region-p)
        (newline))

Not sure if that is now the desired behavior but it confuses me.

Environment & Version information

crux version information

I can't find any crux-version command, but from the package:

;; Package-Version: 20210811.436
;; Package-Commit: 6bfd212a7f7ae32e455802fde1f9e3f4fba932a0
;; Version: 0.4.0

Emacs version

28.0.50

Operating system

gnu/linux (Ubuntu 21.04)

@jeremyf
Copy link

jeremyf commented Nov 20, 2021

Here's the work around that I have:

(defun jnf/duplicate-current-line-or-lines-of-region (arg)
  "Duplicate ARG times current line or the lines of the current region."
  (interactive "p")
  (if (use-region-p)
      (progn
        (when (> (point) (mark))
          (exchange-point-and-mark))
        (beginning-of-line)
        (exchange-point-and-mark)
        (end-of-line)
        (goto-char (+ (point) 1))
        (exchange-point-and-mark)
        (let* ((end (mark))
               (beg (point))
               (region
                (buffer-substring-no-properties beg end)))
          (dotimes (_i arg)
            (goto-char end)
            (insert region)
            (setq end (point)))))
    (crux-duplicate-current-line-or-region arg)))

The behavior is if I'm not acting on a region, use crux-duplicate-current-line-or-region. Otherwise, duplicate each of the lines in the region.

Before:
before

After:
after

Note, this duplicates the entire lines that are in the region (and not the region itself). I find this is the behavior that I most often want.

@TxGVNN
Copy link

TxGVNN commented Mar 16, 2022

Seem this issue came from #80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants