Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8483149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:00:51+00:00 2026-06-10T20:00:51+00:00

From time to time I see people pasting portions of code with reference to

  • 0

From time to time I see people pasting portions of code with reference to the file name and line number. Something like

 ;; ----- line:3391   file: simple.el.gz -----;;; 

 (if (eq last-command 'kill-region)
      (kill-append (filter-buffer-substring beg end) (< end beg))
    (kill-new (filter-buffer-substring beg end)))

 ;; ----- line:3394 --------------------------;;;

This is mainly useful to send comments on code by mail. I can easily wrap a simple function for myself, but I am sure someone have already done this in a smart and pretty way.

Thanks.

[EDIT]

Because this functionality is needed only occasionally, and only for one copy/paste action, I ended up using an alternative solution to the toggling version proposed by @thisirs.

(defun kill-with-linenum (beg end)
  (interactive "r")
  (save-excursion
    (goto-char end)
    (skip-chars-backward "\n \t")
    (setq end (point))
    (let* ((chunk (buffer-substring beg end))
           (chunk (concat
                   (format "╭──────── #%-d ─ %s ──\n│ "
                           (line-number-at-pos beg)
                           (or (buffer-file-name) (buffer-name))
                           )
                   (replace-regexp-in-string "\n" "\n│ " chunk)
                   (format "\n╰──────── #%-d ─" 
                           (line-number-at-pos end)))))
      (kill-new chunk)))
  (deactivate-mark))

It is unicode based and produces this output:

╭──────── #3557 ─ /usr/share/emacs/24.1.50/lisp/simple.el.gz ──
│   (if (eq this-command t)
│       (setq this-command 'yank))
│   nil)
╰──────── #3559 ─
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:00:52+00:00Added an answer on June 10, 2026 at 8:00 pm

    I have come up with this, using wrapper hook:

    (defun filter-buffer-substring-add-line (func beg end delete)
      (concat
       (format ";; line:%5d file: %s\n"
               (line-number-at-pos beg)
               (or (buffer-file-name) (buffer-name)))
       (funcall func beg end delete)
       (format "\n;; line:%5d" (line-number-at-pos end))))
    
    (defun kill-add-line-toggle ()
      (interactive)
      (if (memq 'filter-buffer-substring-add-line
                filter-buffer-substring-functions)
          (progn
            (setq filter-buffer-substring-functions
                  (delq 'filter-buffer-substring-add-line
                        filter-buffer-substring-functions))
            (message "Add line is off!"))
        (push 'filter-buffer-substring-add-line
              filter-buffer-substring-functions)
        (message "Add line is on!")))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From time to time I see something like this: class Clazz { private int
I see, from time to time, that people say that SQL query that is
As the title suggests, I would like to see if this is something people
I want to see if a time I read from a db overlaps with
From time time to time, I'd like to be able to measure the elapsed
I write hobby code from time to time. The thing is these tools, classes
I see people using flock like this: if (!$fp = fopen($file_name, 'wb')) { return
One often needs to read from memory one byte at a time, like in
From time to time, I find myself using the same group of statements and
From time to time I run into the issue that Grails integration tests the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.