From time to time I see people inserting portions of code with a link to the file name and line number. Sort of
;; ----- 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 mostly useful for posting comments by code. I can easily wrap a simple function for myself, but I'm sure someone has already done this in a smart and beautiful way.
Thanks.
[EDIT]
Since this functionality is only needed occasionally, and for only one copy / paste action, I ended up using an alternative solution for the switchable 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 based on Unicode 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 β
source share