unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#25454: 25.1; improvement ftoopy-from-above-command
@ 2017-01-15 20:00 Francesco Potortì
  2019-07-27 10:35 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Francesco Potortì @ 2017-01-15 20:00 UTC (permalink / raw)
  To: 25454

This is the version I use:

it copies line from above as the stock one, but when called repeatedly
it copies from further above lines.  Moreover, when called with a
numeric argument, increments all the numbers fund in the copied text by
the argument.

;; Modified from misc.el distributed with 19.30
;; by "Francesco Potortì <F.Potorti@isti.cnr.it>"

(defvar my-copy-from-above-lines -1)
(defvar my-copy-from-above-chars 0)
(defvar my-copy-from-above-inc 0)

(defun my-copy-from-above-command (&optional arg)
  "Copy the previous line incrementing numbers, starting just above point.

All integer numbers fetched as part of the line are incremented by ARG.
If no argument is given, numbers are left as they are.
Successive invocations of this command fetch successively previous lines.
The characters copied are inserted in the buffer before point, mark is
set to the beginning of the inserted string."
  (interactive "P")
  (if (eq last-command 'copy-from-above-command)
      (progn
	(delete-char (- copy-from-above-chars))
	(setq copy-from-above-lines (1- copy-from-above-lines)))
    (push-mark)
    (setq copy-from-above-lines -1)
    (setq copy-from-above-inc (if arg (prefix-numeric-value arg) 0)))
  (let ((cc (current-column))
	(string ""))
    (save-excursion
      (forward-line copy-from-above-lines)
      (move-to-column cc)
      ;; If current column winds up in middle of a tab,
      ;; copy appropriate number of "virtual" space chars.
      (if (< cc (current-column))
	  (if (= (preceding-char) ?\t)
	      (setq string (make-string (- (current-column) cc) ?\ ))
	    ;; In middle of ctl char => copy that whole char.
	    (backward-char 1)))
      (setq string (concat string
			   (buffer-substring (point)
					     (save-excursion
					       (end-of-line) (point))))))
    (let ((index 0)
	  (oldstr "")
	  (newstr ""))
      (while (string-match "[0-9]+" string index)
	(setq oldstr (match-string 0 string))
	(setq newstr
	      (format
	       (concat "%0" (int-to-string (length oldstr)) "d")
	       (+ copy-from-above-inc (string-to-number oldstr))))
	(setq index (+ (match-beginning 0) (length newstr)))
	(setq string (replace-match newstr nil nil string))))
    (setq copy-from-above-chars (length string))
    (insert string)))

(global-set-key "\M-p" 'my-copy-from-above-command)


In GNU Emacs 25.1.1 (x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2016-10-24, modified by Debian built on trouble
Windowing system distributor 'The X.Org Foundation', version 11.0.11900000
System Description:	Debian GNU/Linux testing (stretch)

Configured using:
 'configure --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/lib
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs25:/etc/emacs:/usr/local/share/emacs/25.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/25.1/site-lisp:/usr/share/emacs/site-lisp
 --with-sound=alsa --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/lib
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs25:/etc/emacs:/usr/local/share/emacs/25.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/25.1/site-lisp:/usr/share/emacs/site-lisp
 --with-sound=alsa --with-x=yes --with-x-toolkit=lucid
 --with-toolkit-scroll-bars --without-gconf --without-gsettings
 'CFLAGS=-g -O2
 -fdebug-prefix-map=/build/emacs25-25.1+1=. -fstack-protector-strong
 -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time
 -D_FORTIFY_SOURCE=2' LDFLAGS=-Wl,-z,relro'

Configured features:
XAW3D XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS NOTIFY ACL
LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS LUCID X11

Important settings:
  value of $LC_COLLATE: it_IT.UTF-8
  value of $LC_CTYPE: it_IT.UTF-8
  value of $LC_NUMERIC: C
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Text

Minor modes in effect:
  filladapt-mode: t
  global-visual-fill-column-mode: t
  diff-auto-refine-mode: t
  TeX-PDF-mode: t
  desktop-save-mode: t
  epa-global-mail-mode: t
  shell-dirtrack-mode: t
  openwith-mode: t
  xterm-mouse-mode: t
  display-time-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  auto-fill-function: do-auto-fill

Recent messages:
No following nondeleted message
Expunging deleted messages...done
Computing summary lines...done
Showing message 897...
Saving file /home/pot/Mail/RMAIL...
Wrote /home/pot/Mail/RMAIL [2 times]
Showing message 1363...done
(No new mail has arrived)
0 new messages read
Showing message 1363...done

Load-path shadows:
~/elisp/bhl hides /usr/share/emacs/site-lisp/bhl
/usr/share/emacs25/site-lisp/flim/md4 hides /usr/share/emacs/25.1/lisp/md4
/usr/share/emacs25/site-lisp/flim/hex-util hides /usr/share/emacs/25.1/lisp/hex-util
/usr/share/emacs/site-lisp/rst hides /usr/share/emacs/25.1/lisp/textmodes/rst
~/elisp/bibtex hides /usr/share/emacs/25.1/lisp/textmodes/bibtex
/usr/share/emacs25/site-lisp/flim/ntlm hides /usr/share/emacs/25.1/lisp/net/ntlm
/usr/share/emacs25/site-lisp/flim/hmac-md5 hides /usr/share/emacs/25.1/lisp/net/hmac-md5
/usr/share/emacs25/site-lisp/flim/sasl-ntlm hides /usr/share/emacs/25.1/lisp/net/sasl-ntlm
/usr/share/emacs25/site-lisp/flim/sasl-digest hides /usr/share/emacs/25.1/lisp/net/sasl-digest
/usr/share/emacs25/site-lisp/flim/sasl hides /usr/share/emacs/25.1/lisp/net/sasl
/usr/share/emacs25/site-lisp/flim/sasl-cram hides /usr/share/emacs/25.1/lisp/net/sasl-cram
/usr/share/emacs25/site-lisp/flim/hmac-def hides /usr/share/emacs/25.1/lisp/net/hmac-def
/usr/share/emacs25/site-lisp/auctex/tex-fold hides /usr/share/emacs/site-lisp/auctex/tex-fold
/usr/share/emacs25/site-lisp/auctex/context-en hides /usr/share/emacs/site-lisp/auctex/context-en
/usr/share/emacs25/site-lisp/auctex/tex-info hides /usr/share/emacs/site-lisp/auctex/tex-info
/usr/share/emacs25/site-lisp/auctex/plain-tex hides /usr/share/emacs/site-lisp/auctex/plain-tex
/usr/share/emacs25/site-lisp/auctex/tex-mik hides /usr/share/emacs/site-lisp/auctex/tex-mik
/usr/share/emacs25/site-lisp/auctex/texmathp hides /usr/share/emacs/site-lisp/auctex/texmathp
/usr/share/emacs25/site-lisp/auctex/context-nl hides /usr/share/emacs/site-lisp/auctex/context-nl
/usr/share/emacs25/site-lisp/auctex/toolbar-x hides /usr/share/emacs/site-lisp/auctex/toolbar-x
/usr/share/emacs25/site-lisp/auctex/tex hides /usr/share/emacs/site-lisp/auctex/tex
/usr/share/emacs25/site-lisp/auctex/tex-jp hides /usr/share/emacs/site-lisp/auctex/tex-jp
/usr/share/emacs25/site-lisp/auctex/bib-cite hides /usr/share/emacs/site-lisp/auctex/bib-cite
/usr/share/emacs25/site-lisp/auctex/multi-prompt hides /usr/share/emacs/site-lisp/auctex/multi-prompt
/usr/share/emacs25/site-lisp/auctex/font-latex hides /usr/share/emacs/site-lisp/auctex/font-latex
/usr/share/emacs25/site-lisp/auctex/prv-emacs hides /usr/share/emacs/site-lisp/auctex/prv-emacs
/usr/share/emacs25/site-lisp/auctex/tex-style hides /usr/share/emacs/site-lisp/auctex/tex-style
/usr/share/emacs25/site-lisp/auctex/context hides /usr/share/emacs/site-lisp/auctex/context
/usr/share/emacs25/site-lisp/auctex/preview hides /usr/share/emacs/site-lisp/auctex/preview
/usr/share/emacs25/site-lisp/auctex/tex-font hides /usr/share/emacs/site-lisp/auctex/tex-font
/usr/share/emacs25/site-lisp/auctex/tex-bar hides /usr/share/emacs/site-lisp/auctex/tex-bar
/usr/share/emacs25/site-lisp/auctex/latex hides /usr/share/emacs/site-lisp/auctex/latex
/usr/share/emacs25/site-lisp/auctex/tex-buf hides /usr/share/emacs/site-lisp/auctex/tex-buf
~/elisp/bhl hides /usr/share/emacs25/site-lisp/bhl
/usr/share/emacs/site-lisp/debian-startup hides /usr/share/emacs25/site-lisp/debian-startup

Features:
(find-dired loadhist novice wdired animate misc ruler-mode cal-x debug
two-column iso-transl apropos pcmpl-gnu pcmpl-linux macros python
tramp-sh tar-mode anything-config anything woman mailcap undigest
cal-move smerge-mode diff doc-view vc-cvs pcmpl-unix json-mode rx
cus-edit wid-edit cus-start cus-load rmailedit tabify man vc-dir ewoc
tramp-cache shadow emacsbug reporter debian-bug mail-extr texmathp
nxml-uchnm rng-xsd xsd-regexp rng-cmpct rng-nxml rng-valid rng-loc
rng-uri rng-parse nxml-parse rng-match rng-dt rng-util rng-pttrn nxml-ns
nxml-mode nxml-outln nxml-rap nxml-util nxml-glyph nxml-enc xmltok tmm
ido etags xref project ediff-merg ediff-wind ediff-diff ediff-mult
ediff-help ediff-init ediff-util ediff js json map imenu ispell log-view
pp visual-fill-column locate dired-aux eieio-opt speedbar sb-image
ezimage dframe find-func timezone rmailsort face-remap url-handlers nero
cl rect log-edit pcvs-util add-log grep dabbrev diff-mode vc rmailkwd
mailalias rmailout shr-color color time-stamp misearch multi-isearch
server parse-time unrmail qp url-util shr dom subr-x browse-url
jka-compr cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align
cc-engine cc-vars cc-defs bibtex info sh-script executable sgml-mode
vc-filewise vc-rcs image-mode view conf-mode generic octave smie
latexenc plain-tex vc-dispatcher vc-svn preview prv-emacs tex-bar
tex-buf toolbar-x noutline outline font-latex latex easy-mmode edmacro
kmacro tex-style tex dbus xml crm tex-mode compile rmailmm message
rfc822 mml mml-sec mm-decode mm-bodies mm-encode mailabbrev gmm-utils
mailheader mail-parse rfc2231 desktop frameset term/xterm xterm pot
skeleton rmailsum rmail warnings sendmail rfc2047 rfc2045 ietf-drums
mime-compose epa-mail mail-utils epa derived epg cal-china lunar solar
cal-dst cal-bahai cal-islam cal-hebrew holidays hol-loaddefs vc-hg appt
diary-lib diary-loaddefs cal-menu calendar cal-loaddefs tramp
tramp-compat tramp-loaddefs trampver ucs-normalize shell pcomplete
comint ring format-spec bhl switch-to-shell openwith hi-lock xt-mouse
ffap thingatpt url-parse auth-source cl-seq eieio eieio-core cl-macs
gnus-util time-date mm-util help-fns mail-prsvr password-cache url-vars
scroll-in-place filladapt ansi-color advice time quail dired-x dired
generic-x disp-table finder-inf package epg-config seq byte-opt gv
bytecomp byte-compile cl-extra help-mode easymenu cconv cl-loaddefs
pcase cl-lib debian-el debian-el-loaddefs w3m-load vm-autoload
vm-autoloads vm-version vm-vars vm-init preview-latex tex-site
auto-loads mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel x-win term/common-win x-dnd tool-bar dnd fontset
image regexp-opt fringe tabulated-list newcomment elisp-mode lisp-mode
prog-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cl-generic cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese charscript case-table epa-hook
jka-cmpr-hook help simple abbrev minibuffer cl-preloaded nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote dbusbind inotify dynamic-setting
font-render-setting x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 1167121 238907)
 (symbols 48 60626 41)
 (miscs 40 7205 6060)
 (strings 32 175459 30474)
 (string-bytes 1 5173380)
 (vectors 16 86824)
 (vector-slots 8 2196884 87712)
 (floats 8 1410 1185)
 (intervals 56 165132 8825)
 (buffers 976 242))






^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#25454: 25.1; improvement ftoopy-from-above-command
  2017-01-15 20:00 bug#25454: 25.1; improvement ftoopy-from-above-command Francesco Potortì
@ 2019-07-27 10:35 ` Lars Ingebrigtsen
  2019-07-27 11:29   ` Noam Postavsky
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-27 10:35 UTC (permalink / raw)
  To: Francesco Potortì; +Cc: 25454

Francesco Potortì <pot@gnu.org> writes:

> This is the version I use:
>
> it copies line from above as the stock one, but when called repeatedly
> it copies from further above lines.  Moreover, when called with a
> numeric argument, increments all the numbers fund in the copied text by
> the argument.

This seems pretty useful, but it's an incompatible change, since ARG is
currently:

Copy ARG characters, but not past the end of that line.

So I don't think this would be a candidate for inclusion in Emacs, but
perhaps it could be rewritten and made into a M/ELPA package?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#25454: 25.1; improvement ftoopy-from-above-command
  2019-07-27 10:35 ` Lars Ingebrigtsen
@ 2019-07-27 11:29   ` Noam Postavsky
  2019-07-27 11:32     ` Lars Ingebrigtsen
       [not found]     ` <E1i3IDK-0007DM-JK@tucano.isti.cnr.it>
  0 siblings, 2 replies; 8+ messages in thread
From: Noam Postavsky @ 2019-07-27 11:29 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 25454

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Francesco Potortì <pot@gnu.org> writes:
>
>> This is the version I use:
>>
>> it copies line from above as the stock one, but when called repeatedly
>> it copies from further above lines.  Moreover, when called with a
>> numeric argument, increments all the numbers fund in the copied text by
>> the argument.
>
> This seems pretty useful, but it's an incompatible change, since ARG is
> currently:
>
> Copy ARG characters, but not past the end of that line.
>
> So I don't think this would be a candidate for inclusion in Emacs, but
> perhaps it could be rewritten and made into a M/ELPA package?

Seems a bit small for a separate package.  And the repeated call thing
could be useful in itself.  Couldn't the increment behaviour be enabled
by a non-numeric argument instead?






^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#25454: 25.1; improvement ftoopy-from-above-command
  2019-07-27 11:29   ` Noam Postavsky
@ 2019-07-27 11:32     ` Lars Ingebrigtsen
  2019-07-28 20:50       ` Juri Linkov
       [not found]     ` <E1i3IDK-0007DM-JK@tucano.isti.cnr.it>
  1 sibling, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-27 11:32 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: 25454

Noam Postavsky <npostavs@gmail.com> writes:

> Seems a bit small for a separate package.  And the repeated call thing
> could be useful in itself.  Couldn't the increment behaviour be enabled
> by a non-numeric argument instead?

Hm...  I guess that's possible.  But the "copy the previous line but
increase the numbers" seems like a somewhat obscure thing to add to a
command like that, but perhaps I'm just not seeing the use case.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#25454: 25.1; improvement ftoopy-from-above-command
  2019-07-27 11:32     ` Lars Ingebrigtsen
@ 2019-07-28 20:50       ` Juri Linkov
  0 siblings, 0 replies; 8+ messages in thread
From: Juri Linkov @ 2019-07-28 20:50 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Noam Postavsky, 25454

>> Seems a bit small for a separate package.  And the repeated call thing
>> could be useful in itself.  Couldn't the increment behaviour be enabled
>> by a non-numeric argument instead?
>
> Hm...  I guess that's possible.  But the "copy the previous line but
> increase the numbers" seems like a somewhat obscure thing to add to a
> command like that, but perhaps I'm just not seeing the use case.

What I do in these cases is copy the current line ARG times,
and then use query-replace with \# to increment numbers.
I prefer query-replace for its flexibility since numeric formats
and initial numeric values vary wildly.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#25454: 25.1; improvement ftoopy-from-above-command
       [not found]     ` <E1i3IDK-0007DM-JK@tucano.isti.cnr.it>
@ 2019-08-30  9:52       ` Lars Ingebrigtsen
  2019-08-31 12:17         ` Francesco Potortì
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2019-08-30  9:52 UTC (permalink / raw)
  To: Francesco Potortì; +Cc: Noam Postavsky, 25454

Francesco Potortì <pot@gnu.org> writes:

>>Seems a bit small for a separate package.  And the repeated call thing
>>could be useful in itself.  Couldn't the increment behaviour be enabled
>>by a non-numeric argument instead?
>
> What do you suggest?  Maybe M-3 M-p copies the next three characters,
> while C-u 3 M-p increments by three?

M-3 and C-u 3 do the same thing, I think?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#25454: 25.1; improvement ftoopy-from-above-command
  2019-08-30  9:52       ` Lars Ingebrigtsen
@ 2019-08-31 12:17         ` Francesco Potortì
  2019-09-01 13:57           ` Noam Postavsky
  0 siblings, 1 reply; 8+ messages in thread
From: Francesco Potortì @ 2019-08-31 12:17 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 25454, Noam Postavsky

>>Lars:
>>>Seems a bit small for a separate package.  And the repeated call thing
>>>could be useful in itself.  Couldn't the increment behaviour be enabled
>>>by a non-numeric argument instead?

>Francesco Potortì <pot@gnu.org> writes:
>> What do you suggest?  Maybe M-3 M-p copies the next three characters,
>> while C-u 3 M-p increments by three?

>M-3 and C-u 3 do the same thing, I think?

They normally do.  And they do in this case.  But it can be changed, and
I was following up with your suggestion, with a proposal for a different
user interface where M-3 and C-u 3 do different things.

However, as I explaind in a previous message, I suspect that the current
default behaviour is useless.  It is certainly useless to me, which is
why I overrode the meaning of the numerical prefix.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#25454: 25.1; improvement ftoopy-from-above-command
  2019-08-31 12:17         ` Francesco Potortì
@ 2019-09-01 13:57           ` Noam Postavsky
  0 siblings, 0 replies; 8+ messages in thread
From: Noam Postavsky @ 2019-09-01 13:57 UTC (permalink / raw)
  To: Francesco Potortì; +Cc: Lars Ingebrigtsen, 25454

Francesco Potortì <pot@gnu.org> writes:

>>>Lars:
>>>>Seems a bit small for a separate package.  And the repeated call thing
>>>>could be useful in itself.  Couldn't the increment behaviour be enabled
>>>>by a non-numeric argument instead?
>
>>Francesco Potortì <pot@gnu.org> writes:
>>> What do you suggest?  Maybe M-3 M-p copies the next three characters,
>>> while C-u 3 M-p increments by three?
>
>>M-3 and C-u 3 do the same thing, I think?
>
> They normally do.  And they do in this case.  But it can be changed, and
> I was following up with your suggestion, with a proposal for a different
> user interface where M-3 and C-u 3 do different things.

No, both C-u 3 and M-3 will set the prefix argument to 3, so commands
cannot distinguish between them.  I know I suggested the numeric vs
non-numeric thing, but I think I was just confused about it.
Non-numeric arguments are only good for a single toggle (increment vs no
increment), not control over a amount (increment by X).  And you can't
express both at once (both increment and repeat).





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-09-01 13:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-15 20:00 bug#25454: 25.1; improvement ftoopy-from-above-command Francesco Potortì
2019-07-27 10:35 ` Lars Ingebrigtsen
2019-07-27 11:29   ` Noam Postavsky
2019-07-27 11:32     ` Lars Ingebrigtsen
2019-07-28 20:50       ` Juri Linkov
     [not found]     ` <E1i3IDK-0007DM-JK@tucano.isti.cnr.it>
2019-08-30  9:52       ` Lars Ingebrigtsen
2019-08-31 12:17         ` Francesco Potortì
2019-09-01 13:57           ` Noam Postavsky

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).