Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
emacs
emacs
Commits
2845f6fd
Commit
2845f6fd
authored
Jul 29, 2009
by
Jay Belanger
Browse files
(calctransposelines): New function.
parent
905fb90e
Changes
1
Hide whitespace changes
Inline
Sidebyside
Showing
1 changed file
with
114 additions
and
1 deletion
+114
1
lisp/calc/calcmisc.el
lisp/calc/calcmisc.el
+114
1
No files found.
lisp/calc/calcmisc.el
View file @
2845f6fd
...
...
@@ 57,7 +57,7 @@
(
declarefunction
mathpowofzero
"calcarith"
(
a
b
))
(
declarefunction
mathpowzero
"calcarith"
(
a
b
))
(
declarefunction
mathpowfancy
"calcarith"
(
a
b
))
(
declarefunction
calclocatecursorelement
"calcyank"
(
pt
))
;;;###autoload
(
defun
calcdispatchhelp
(
arg
)
...
...
@@ 452,6 +452,119 @@ Calc user interface as before (either Cx * C or Cx * K; initially Cx * C).
(
t
(
calcrollupstack
(
calcstacksize
)
(

nn
)))))))
;;;###autoload
(
defun
calctransposelines
(
&optional
arg
)
"Transpose previous line and current line.
With argument ARG, move previous line past ARG lines.
With argument 0, switch line point is in with line mark is in."
(
interactive
"p"
)
(
setq
arg
(
or
arg
1
))
(
let
(
botline
midline
endline
oldtoplist
newtoplist
botcell
midcell
prevmidcell
postmidcell
postbotcell
)
(
calcwrapper
(
when
(
eq
majormode
'calcmode
)
(
cond
;; exchange point and mark
((
=
0
arg
)
(
setq
botline
(
calclocatecursorelement
(
point
))
midline
(
mark
))
(
if
midline
(
setq
midline
(
calclocatecursorelement
midline
)
endline
(
1+
midline
))
(
error
"No mark set"
))
(
if
(
<
botline
midline
)
(
let
((
temp
midline
))
(
setq
midline
botline
botline
temp
))))
;; move botline to midline that is above botline on stack (that is
;; to say midline displayed below botline in *Calculator* buffer)
((
>
arg
0
)
(
setq
botline
(
1+
(
calclocatecursorelement
(
point
)))
midline
(

botline
arg
)
endline
midline
))
;; move botline to midline that is above botline on stack (that is
;; to say midline displayed below botline in *Calculator* buffer)
((
<
arg
0
)
(
setq
midline
(
1+
(
calclocatecursorelement
(
point
)))
botline
(

midline
arg
)
endline
botline
)))
(
calccheckstack
botline
)
(
if
(
=
0
midline
)
(
error
"Can't transpose beyond top"
))
(
setq
oldtoplist
(
nreverse
(
calctoplist
botline
)))
;; example: (arg = 2)
;; oldtoplist =
;; 1 < top of stack (bottom of *Calculator* buffer)
;; 2
;; 3 < midline = 3
;; 4 < point
;; 5 < botline = 5
(
dotimes
(
i
midline
)
(
setq
midcell
oldtoplist
oldtoplist
(
cdr
oldtoplist
))
(
setcdr
midcell
newtoplist
)
(
setq
newtoplist
midcell
))
;; example followup:
;; oldtoplist =
;; 4
;; 5
;; newtoplist =
;; 3 < midcell
;; 2
;; 1
(
setq
prevmidcell
oldtoplist
)
(
dotimes
(
i
(

botline
midline
))
(
setq
botcell
oldtoplist
oldtoplist
(
cdr
oldtoplist
))
(
setcdr
botcell
newtoplist
)
(
setq
newtoplist
botcell
))
(
setq
postmidcell
(
cdr
midcell
)
postbotcell
(
cdr
botcell
))
;; example followup:
;; newtoplist =
;; 5 < botcell
;; 4 < prevmidcell & postbotcell
;; 3 < midcell
;; 2 < postmidcell
;; 1
(
cond
((
=
0
arg
)
; swap bot and mid
(
setcdr
midcell
postbotcell
)
(
setcdr
botcell
postmidcell
)
(
setcdr
prevmidcell
botcell
)
;; example followup:
;; 3 < midcell
;; 4 < postbotcell & prevmidcell
;; 5 < botcell
;; 2 < postmidcell
;; 1
(
setq
newtoplist
midcell
))
((
<
0
arg
)
; move bot just after mid
(
setcdr
midcell
botcell
)
(
setcdr
botcell
postmidcell
)
;; example followup:
;; newtoplist =
;; 4 < postbotcell
;; 3 < midcell
;; 5 < botcell
;; 2 < postmidcell
;; 1
(
setq
newtoplist
postbotcell
))
((
>
0
arg
)
; move mid just before bot
(
setcdr
midcell
botcell
)
(
setcdr
prevmidcell
postmidcell
)
;; example followup:
;; newtoplist =
;; 3 < midcell
;; 5 < botcell
;; 4 < prevmidcell
;; 2 < postmidcell
;; 1
(
setq
newtoplist
midcell
)))
(
calcpoppushlist
botline
newtoplist
)))
(
calccursorstackindex
(
1
endline
))))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment