-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdove-ext.el
executable file
·1017 lines (840 loc) · 34.2 KB
/
dove-ext.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; dove-ext.el --- Emacs minor extensions written by David young
;; Copyright (C) 2009 David Young <[email protected]>
;; Author: David Young
;; Maintainer: David Young <[email protected]>
;; Keywords: shell,shell-mode, copy, help, tools, convenience
;; URL: http://www.emacswiki.org/cgi-bin/wiki/download/dove-ext.el
;; Site: http://www.emacswiki.org/cgi-bin/emacs/DavidYoung
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;; miscellaneous
(eval-when-compile
(require 'cl))
(require 'cl)
(defun test-get-point (&optional arg)
"test-get-point"
(interactive "P")
(message "%s" (get-point 'forward-word 3)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; shell mode related ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun come-here (&optional arg)
"Bring content from specific buffer to current buffer"
(interactive (list (let (( arg (read-buffer "Input buffer Name: " "*Shell Command Output*") ))
(insert-buffer-substring (get-buffer arg))))))
(defun jump (&optional arg)
"Put current line to another window."
(interactive "P")
(let ((command (comint-get-old-input-default))
(num (or arg 1)))
(progn (other-window num)
;; if in shell-mode, goto shell input prompt, else just insert at point
(if (string= "shell-mode" major-mode)
(progn
(goto-char (point-max))
;; First delete any old unsent input at the end
(delete-region
(or (marker-position comint-accum-marker)
(process-mark (get-buffer-process (current-buffer))))
(point))))
(insert command))))
;(defun some (&optional arg)
; "Delete Shell command output, to which C-c C-o cannot do for you."
; (interactive "P")
; (let ((end
; (get-point '(lambda (&optional arg) "" (interactive "P")
; (comint-previous-prompt (or arg 1))
;; (previous-line) -- this command is for interactive only
; (forward-line -1)
;; (move-beginning-of-line 1)
; (move-end-of-line 1)
; ) arg))
; (start
; (get-point '(lambda (&optional arg) "" (interactive "P")
; (comint-previous-prompt 1)
;; (next-line)
; (move-beginning-of-line 2)
; ) arg))
; )
; (delete-region start end)
; )
;
;)
(defun mywrite-region (&optional string)
"Append current region to specified file. Leverage write-region to implement this function"
(interactive "BInput file name: ")
(write-region (region-beginning) (region-end) string "append"))
(defun matrixSum (start end)
"Calculate matrix statistics by row & column. Then insert result into current buffer."
(interactive "r")
(progn (shell-command-on-region start end "matrixSum")
(let ((buf "*Shell Command Output*"))
(progn (come-here buf) (kill-buffer buf) (delete-other-windows)))))
(defun exitshell(&optional arg)
" Exit from login shell, with prefix to exit many levels "
(interactive "P")
(let (( nlist (make-list (or arg 1) 1) ))
(while nlist
(comint-next-prompt 1)
(insert "exit ")
(comint-send-input)
(sit-for 1)
(pop nlist))))
; The function will ignore command like this
; ssh [email protected] ls bin
; It could response only to command like this
; ssh [email protected]
(add-hook 'shell-mode-hook
(lambda()
(setq shell-buffer-name-list (list "*shell*") )
(message "%s" shell-buffer-name-list)
)
t)
(eval-after-load 'shell
'(progn
; rewrote this function to co-work with rename-buffer-in-ssh-exit
(defun rename-buffer-in-ssh-login (cmd)
"Rename buffer to the destination hostname in ssh login"
(if (string-match "ssh .* [-_a-z0-9A-Z]+@[-_a-z0-9A-Z.]+[ ]*[^-_a-z0-9-A-Z.]*$" cmd)
(let (( host (nth 1 (split-string cmd "[@\n]" t) ))
)
; (message "%s" (split-string cmd "[ @\n]" t) )
(rename-buffer (concat "*" host))
(add-to-list 'shell-buffer-name-list (concat "*" host))
(message "%s" shell-buffer-name-list)
)
)
; (if (string-match "^bash$")
; (add-to-list 'shell-buffer-name-list nil)
; )
)
(add-hook 'comint-input-filter-functions 'rename-buffer-in-ssh-login)
;; This function works only in a single shell session.
;; Not sure how to make it work and safe in multi-session.
;; how to handle commands like 'bash' and then 'exit' is also a problem
;; (defun rename-buffer-in-ssh-exit (cmd)
;; "Rename buffer to its previous name when user exit from a ssh login"
;; ; (message "%s" cmd)
;; (message "%s" shell-buffer-name-list)
;; (if (string-match "^exit$" cmd)
;; (if (> (length shell-buffer-name-list) 1)
;; (progn (pop shell-buffer-name-list)
;; (rename-buffer (car shell-buffer-name-list)))
;; )
;; )
;; (message "%s" shell-buffer-name-list)
;; )
;; (add-hook 'comint-input-filter-functions 'rename-buffer-in-ssh-exit t)
(defun kill-shell-buffer(process event)
"The one actually kill shell buffer when exit. "
(kill-buffer (process-buffer process))
)
(defun kill-shell-buffer-after-exit()
"kill shell buffer when exit."
(set-process-sentinel (get-buffer-process (current-buffer))
#'kill-shell-buffer)
)
(add-hook 'shell-mode-hook 'kill-shell-buffer-after-exit t)
))
(defvar dove-prompt-line 1)
(defun shell-args (&optional cmd)
"echo #4:3 some #2:3 new ; svn diff #2:1:s/win/linux/"
(interactive)
(goto-char (line-end-position))
(comint-kill-input)
(let ((cmd_list (split-string (pop kill-ring)))
(dove_zsh_cmd (list " "))
(process (get-buffer-process (current-buffer))))
(while (> (length cmd_list) 0)
(let ((word (pop cmd_list)))
(if (string-match "^#\\([0-9]\\):\\([0-9]\\)" word)
(let ((row (string-to-number(match-string 1 word)))
(col (string-to-number(match-string 2 word))))
(save-excursion
(forward-line (- -1 (+ row dove-prompt-line))) ; so starts at -1 instead of 0
(let* ((thing-list (split-string (thing-at-point 'line)))
(dest_str (nth (+ -1 col) thing-list))) ; so starts at 1 instead of 0
(if (string-match ":s/\\([a-z]+\\)/\\([a-z]+\\)/" word)
(let ((regex (match-string 1 word))
(dest (match-string 2 word)))
(setq dest_str (replace-regexp-in-string regex dest dest_str))))
(setq dove_zsh_cmd (append dove_zsh_cmd (list dest_str " "))))))
(setq dove_zsh_cmd (append dove_zsh_cmd (list word " "))))))
(pop dove_zsh_cmd) ; pop the prefix blank charactor
(goto-char (process-mark process))
(apply #'insert dove_zsh_cmd)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; copy & paste related ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun insert-buffer-name (&optional arg)
"Insert current buffer name at point"
(interactive (list (let (( arg (read-buffer "Input buffer Name: " (buffer-name (current-buffer))) ))
(insert (buffer-name (get-buffer arg))) ))
)
)
(setq dove-auto-paste-mode-list
'(shell-mode eshell-mode))
(defun dove-paste-condition (&optional arg)
"Return t if major-mode match predefined list"
(member major-mode dove-auto-paste-mode-list))
(defun copy-thing (begin-of-thing end-of-thing &optional arg)
"copy thing between beg & end into kill ring"
(let ((beg (get-point begin-of-thing 1))
(end (get-point end-of-thing arg)))
(copy-region-as-kill beg end)))
(defun get-point (symbol &optional arg)
"get the point"
(progn (funcall symbol arg) (point)))
(defun paste-to-mark(condition &optional arg)
"Paste things to mark, or to the prompt in shell-mode"
(let ((paste
(lambda()
(if (> (length (funcall condition)) 0 )
(progn (comint-next-prompt 25535) (yank))
(progn (goto-char (mark)) (yank))))))
(if (and arg (= arg 1))
nil
(funcall paste))))
(defmacro copy-something-to-mark (begin-fn end-fn arg)
`(progn (copy-thing ,begin-fn ,end-fn ,arg)
(paste-to-mark 'dove-paste-condition ,arg)))
; (macroexpand '(copy-something-to-mark
; beginning-of-string end-of-string arg))
(defun copy-line (&optional arg)
"Copy lines at point and paste them to mark"
(interactive "P")
(copy-something-to-mark 'beginning-of-line 'end-of-line arg))
(defun copy-word (&optional arg)
"Copy words at point and paste them to mark"
(interactive "P")
(copy-something-to-mark 'backward-word 'forward-word arg))
(defun copy-paragraph (&optional arg)
"Copy paragraphes at point and paste them to mark"
(interactive "P")
(copy-something-to-mark 'backward-paragraph 'forward-paragraph arg))
(defun thing-copy-string-to-mark(&optional arg)
"Copy string at point or region selected and paste them to mark"
(interactive "P")
(if (and mark-active transient-mark-mode)
(progn
(copy-region-as-kill (mark) (point))
(pop-mark))
(copy-thing 'beginning-of-string 'end-of-string arg))
(paste-to-mark 'dove-paste-condition arg))
(defun* beginning-of-string(&optional arg (beg "[ \t]"))
" "
(let ((pt (re-search-backward "[ \t]" (line-beginning-position) 3 1)))
(if (looking-at beg)
(goto-char (+ pt 1))
(point))))
(defun end-of-string(&optional arg)
" "
(let ((pt (re-search-forward ".$\\|[ \t,;]" (line-end-position) 3 arg)))
(goto-char (- pt 1)) ;; backward 1 char to avoid to include [ \t,;]
(if (looking-at-p "\\w") ;; move backword in order to avoid use =looking-back=
(goto-char pt)
(point))))
(defun thing-copy-parenthesis-to-mark(&optional arg)
"Copy region between {[(<\"''\">)]} and paste them to mark
Automatic due with nesting {[(<\"''\">)]} characters"
(interactive "P")
(copy-something-to-mark 'beginning-of-parenthesis 'end-of-parenthesis arg))
(defun duplicate-line(&optional arg)
"duplicate current line"
(interactive "P")
(let ((line (thing-at-point 'line)))
(forward-line)
(insert line)
(forward-line -1)
(if arg
(if (> arg 1)
(duplicate-line (- arg 1))))))
(defun dove-forward-kill-word (&optional arg)
"Backward kill word, but do not insert it into kill-wring"
(interactive "P")
(let (( beg (point) )
( end (get-point 'forward-word arg)))
(delete-region beg end)
)
)
(defun go-there(arg)
""
(goto-char (funcall arg)))
(setq dove-parenthesis-list
'( ("[" "]")
("(" ")")
("<" ">")
("{" "}")
("\"" "\"")
("'" "'")
))
(defun beginning-of-parenthesis(&optional arg)
"Go to the beginning of parenthesis
and set the dove-parenthesis-begin found there"
(re-search-backward "[[<(?\'\"]" (line-beginning-position) 3 1)
(if (looking-at "[[<(?\'\"]")
(progn
(goto-char (+ (point) 1))
(setq dove-parenthesis-begin (string (char-before (point))))
)))
(defun end-of-parenthesis(&optional arg)
"Go to the end of parenthesis.
Parenthesis character was defined by beginning-of-parenthesis"
(setq dove-parenthesis-end
(mapconcat (lambda (x)
(if (string= dove-parenthesis-begin (nth 0 x))
(nth 1 x)))
dove-parenthesis-list nil))
(goto-char (+ (point) 1))
(re-search-forward dove-parenthesis-end
(line-end-position) 3 arg)
(if (looking-back dove-parenthesis-end)
(goto-char (- (point) 1))))
(defun backward-symbol (&optional arg)
(interactive "P")
"Go backward a symbol, just like forward-symbol, by provide a -1 arg to it"
(if arg (forward-symbol arg) (forward-symbol -1))
(message "%s" arg))
(defun move-forward-paren (&optional arg)
(interactive "sInput a Parenthesis:")
(message "%s" arg)
(re-search-forward arg (point-max) 3 1))
(defun move-backward-paren (&optional arg)
(interactive "sInput a Parenthesis:")
(message "%s" arg)
(re-search-backward arg (point-max) 3 1))
(defun move-to-the-word (&optional arg)
"Moving to next occurrance of current word"
(interactive "P")
(let (( cur-word (current-word nil nil) ))
(message "%s" cur-word)
(search-forward cur-word)))
(defun back-to-the-word (&optional arg)
"Moving to next occurrance of current word"
(interactive "P")
(let (( cur-word (current-word nil nil) ))
(message "%s" cur-word)
(search-backward cur-word)))
(defun convert-Table(start end)
"Convert Emacs table into HTML table"
(interactive "r")
(shell-command-on-region start end "sed -e 's%^.%<tr><td>&%' -e 's% *%</td><td>%g' -e 's%<td>$%</tr>%'")
(set-buffer "*Shell Command Output*")
; (beginning-of-buffer)
(goto-char (point-min))
(insert "<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n")
; (end-of-buffer)
(goto-char (point-max))
(insert "</table>\n"))
; Conflict with an existing function
;
; insert-line-number is an interactive Lisp function in `basic-edit-toolkit.el'.
;
; (insert-line-number BEG END &optional START-LINE)
;
; Insert line numbers into buffer.
; (defun insert-line-number(&optional arg)
; "Insert a numeric sequence at beginning of each line"
; (interactive "P")
; (let ((insert-number
; (lambda (start beg end)
; "insert a numeric sequence at beginning of each line"
; (goto-char beg)
; (beginning-of-line)
; (insert (number-to-string start))
; (setq start (+ start 1))
; (while (< (point) end)
; (beginning-of-line 2)
; (insert (number-to-string start))
; (setq start (+ start 1))))))
; (cond
; ((or mark-active transient-mark-mode)
; (if (> (point) (mark))
; (exchange-point-and-mark))
; (if arg
; (funcall insert-number arg (point) (mark))
; (funcall insert-number 0 (point) (mark)))
; )
; (t
; (if arg
; (funcall insert-number arg (point-min) (point-max))
; (funcall insert-number 0 (point-min) (point-max)))
; ))))
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; window layout related ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; +-----------------------+----------------------+
; | | |
; | | |
; | | |
; +-----------------------+----------------------+
; | | |
; | | |
; | | |
; +-----------------------+----------------------+
(defun split-window-4()
"Splite window into 4 sub-window"
(interactive)
(if (= 1 (length (window-list)))
(progn (split-window-vertically)
(split-window-horizontally)
(other-window 2)
(split-window-horizontally))))
; +----------------------+ +---------- +----------+
; | | \ | | |
; | | +-------+\ | | |
; +----------------------+ +-------+/ | | |
; | | / | | |
; | | | | |
; +----------------------+ +---------- +----------+
;
; +--------- +-----------+ +----------------------+
; | | | \ | |
; | | | +-------+\ | |
; | | | +-------+/ +----------------------+
; | | | / | |
; | | | | |
; +--------- +-----------+ +----------------------+
(defun change-split-type-2 (&optional arg)
"Changes splitting from vertical to horizontal and vice-versa"
(interactive "P")
(let ((split-type (lambda (&optional arg)
(delete-other-windows-internal)
(if arg (split-window-vertically)
(split-window-horizontally)))))
(change-split-type split-type arg)))
; +-----------------------+ +----------- +-----------+
; | | / \ | | |
; | | /+-------+\ | | |
; +-----------------------+ \+-------+/ | |-----------|
; | | | \ / | | |
; | | | | | |
; +-----------------------+ +----------- +-----------+
; +-----------------------+ +----------- +-----------+
; | | / \ | | |
; | | /+-------+\ | | |
; +-----------------------+ \+-------+/ |------------| |
; | | | \ / | | |
; | | | | | |
; +-----------------------+ +----------- +-----------+
; +-----------------------+ +----------- +-----------+
; | | | / \ | | |
; | | | /+-------+\ | | |
; +-----------------------+ \+-------+/ |------------| |
; | | \ / | | |
; | | | | |
; +-----------------------+ +----------- +-----------+
; +-----------------------+ +----------- +-----------+
; | | | / \ | | |
; | | | /+-------+\ | | |
; +-----------------------+ \+-------+/ | |-----------|
; | | \ / | | |
; | | | | |
; +-----------------------+ +----------- +-----------+
(defun change-split-type (split-fn &optional arg)
"Change 3 window style from horizontal to vertical and vice-versa"
(let ((bufList (mapcar 'window-buffer (window-list))))
(select-window (get-largest-window))
(funcall split-fn arg)
(mapcar* 'set-window-buffer (window-list) bufList)))
(defun change-split-type-3-v (&optional arg)
"change 3 window style from horizon to vertical"
(interactive "P")
(change-split-type 'split-window-3-horizontally arg))
(defun change-split-type-3-h (&optional arg)
"change 3 window style from vertical to horizon"
(interactive "P")
(change-split-type 'split-window-3-vertically arg))
(defun split-window-3-horizontally (&optional arg)
"Split window into 3 while largest one is in horizon"
(interactive "P")
(delete-other-windows)
(split-window-horizontally)
(if arg (other-window 1))
(split-window-vertically))
(defun split-window-3-vertically (&optional arg)
"Split window into 3 while largest one is in vertical"
(interactive "P")
(delete-other-windows)
(split-window-vertically)
(if arg (other-window 1))
(split-window-horizontally))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;(defmacro dove-change-3-buffers ((buf_1 buf_2 buf_3) &body body)
; `(progn (select-window (get-largest-window))
; (if (= 3 (length (window-list)))
; (let ((winList (window-list)))
; (let ((1stWin (car winList))
; (2ndWin (car (cdr winList)))
; (3rdWin (car (cdr (cdr winList)))))
; (let ((1stBuf (window-buffer 1stWin))
; (2ndBuf (window-buffer 2ndWin))
; (3rdBuf (window-buffer 3rdWin)))
; (progn ,@body)))))))
;
;(macroexpand '(dove-change-3-buffers
; (3rdBuf 1stBuf 2ndBuf))
; (progn
; (set-window-buffer 1stWin ,buf_1)
; (set-window-buffer 2ndWin ,buf_2)
; (set-window-buffer 3rdWin ,buf_3)))
;
;; (lambda () (message "%s" '123))))
;
;
;(defun change-split-type-3 ()
; "Change 3 window style from horizontal to vertical and vice-versa"
; (interactive)
; (select-window (get-largest-window))
; (if (= 3 (length (window-list)))
; (let ((winList (window-list)))
; (let ((1stBuf (window-buffer (car winList)))
; (2ndBuf (window-buffer (car (cdr winList))))
; (3rdBuf (window-buffer (car (cdr (cdr winList)))))
;
; (split-3
; (lambda(1stBuf 2ndBuf 3rdBuf split-1 split-2)
; "change 3 window from horizontal to vertical and vice-versa"
; (message "%s %s %s" 1stBuf 2ndBuf 3rdBuf)
;
; (delete-other-windows)
; (funcall split-1)
; (set-window-buffer nil 2ndBuf)
; (funcall split-2)
; (set-window-buffer (next-window) 3rdBuf)
; (other-window 2)
; (set-window-buffer nil 1stBuf)))
;
; (split-type-1 nil)
; (split-type-2 nil)
; )
; (if (= (window-width) (frame-width))
; (setq split-type-1 'split-window-horizontally
; split-type-2 'split-window-vertically)
; (setq split-type-1 'split-window-vertically
; split-type-2 'split-window-horizontally))
; (funcall split-3 1stBuf 2ndBuf 3rdBuf split-type-1 split-type-2)
;
;))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; +----------- +-----------+ +----------- +-----------+
; | | C | \ | | A |
; | | | +-------+\ | | |
; | A |-----------| +-------+/ | B |-----------|
; | | B | / | | C |
; | | | | | |
; +----------- +-----------+ +----------- +-----------+
;
; +------------------------+ +------------------------+
; | A | \ | B |
; | | +-------+\ | |
; +------------------------+ +-------+/ +------------------------+
; | B | C | / | C | A |
; | | | | | |
; +------------------------+ +------------------------+
(defmacro dove-roll-buffers (sort_fn)
`(progn (select-window (get-largest-window))
(let ((winList (window-list)) ; sort buffer list by plugin function sort_fn
(bufferList (funcall ,sort_fn (mapcar 'window-buffer (window-list)))))
(mapcar* (lambda (win buf)
"set bufffer to window"
(set-window-buffer win buf))
winList bufferList))))
(defun roll-3-buffers (&optional arg)
"Roll 3 window buffers clockwise and anti-clockwise"
(interactive "P")
(if arg
(dove-roll-buffers #'(lambda (bufList) ; put the last to the first
(cons (car (last bufList)) (butlast bufList))))
(dove-roll-buffers #'(lambda (bufList) ; put the first to the last
(append (cdr bufList) (list (car bufList)))))))
;; (defun roll-3-buffers-anti-clockwise ()
;; "Roll 3 window buffers anti-clockwise"
;; (interactive)
;; (if (= 3 (length (window-list)))
;; (dove-roll-buffers '(lambda (bufList) ; put the last to the first
;; (cons (car (last bufList)) (butlast bufList))))))
;;
;; (defun roll-3-buffers-clockwise ()
;; "Roll 3 window buffers clockwise"
;; (interactive)
;; (if (= 3 (length (window-list)))
;; (dove-roll-buffers '(lambda (bufList) ; put the first to the last
;; (append (cdr bufList) (list (car bufList)))))))
;(defun dove-hide-shell-output()
; "Hide Shell Output"
; (interactive)
;; (let ((beg (progn (move-end-of-line 0) (point))))
;; (end (progn (comint-previous-prompt 0) (move-beginning-of-line 2) (point)
;;
;; (set-mark-command (progn (move-end-of-line 0) (point)))
; (let ((start (point)))
; (progn
; (comint-previous-prompt 1)
; (move-beginning-of-line 2)
; (set-mark (point))
; (comint-next-prompt 1)
; (move-end-of-line -1)
; (hide-region-hide)
; (set-mark start))
; )
;)
;; edit related
;(defun try-expand-dabbrev-path (old)
; (setq hippie-expand-dabbrev-as-symbol nil)
; (try-expand-dabbrev old)
; (setq hippie-expand-dabbrev-as-symbol t)
;)
;(message "%s" hippie-expand-try-functions-list)
(setq hippie-expand-try-functions-list
(append (list (car hippie-expand-try-functions-list)
'try-expand-dabbrev-path)
(cdr hippie-expand-try-functions-list)
)
)
(defun my-overwrite (&optional arg)
"Encapsulate overwrite-mode function, to enable red alert in mode-line "
(interactive "P")
(if (not overwrite-mode)
(progn (add-to-list 'mode-line-format (propertize overwrite-mode-textual 'face '(:foreground "white" :background "red") ))
(setq my-overwrite-mode-line (car mode-line-format))
(overwrite-mode 1)
)
(progn (overwrite-mode 0)
(if (memq my-overwrite-mode-line mode-line-format)
(setq mode-line-format (delq my-overwrite-mode-line mode-line-format))) )))
; auto-type
(defun i-babel-quote (beg end str1 str2)
(goto-char end)
(forward-line 1)
(insert str2)
(newline)
(goto-char beg)
(forward-line -1)
(newline)
(insert str1))
(defun i-babel-quote-str (beg end Str)
""
(goto-char end)
(insert Str)
(goto-char beg)
(insert Str)
(goto-char (+ end 2)))
(defun iexp (St Ed)
"Enclose example for org-mode"
(interactive "r")
(i-babel-quote St Ed "#+BEGIN_EXAMPLE" "#+END_EXAMPLE"))
(defun isrc (St Ed)
"Enclose code for org-mode"
(interactive "r")
(i-babel-quote St Ed "#+begin_src " "#+end_src"))
(defun ihtml (St Ed)
"Enclose code for Emacser.cn"
(interactive "r")
(i-babel-quote St Ed
(concat "#+BEGIN_HTML\n " "<pre lang=\"lisp\" line=\"1\">\n")
(concat "</pre>\n" "#+END_HTML\n")))
(defmacro dove-org-babel-shortcut-para (str-begin str-end &optional arg)
`(i-babel-quote (+ (progn (backward-paragraph) (point)) 1)
(- (progn (forward-paragraph arg) (point)) 1)
,str-begin ,str-end))
(defun iexp-para (&optional arg)
"Enclose code at point for org-mode"
(interactive "P")
(dove-org-babel-shortcut-para "#+BEGIN_EXAMPLE" "#+END_EXAMPLE" arg))
(defun isrc-para (&optional arg)
"Enclose code at point for org-mode"
(interactive "P")
(dove-org-babel-shortcut-para "#+begin_src " "#+end_src" arg))
(defmacro dove-org-babel-shortcut (x &optional arg)
`(cond
((and mark-active transient-mark-mode)
(let* ((mark (mark)) (point (point))
(St (min mark point))
(Ed (max mark point)))
(i-babel-quote-str St Ed ,x)))
(t
(let ((St (beginning-of-string))
(Ed (end-of-string arg)))
(i-babel-quote-str St Ed ,x)))))
;(macroexpand '(dove-org-babel-shortcut "*" 2))
; (macroexpand '(dove-org-babel-shortcut St Ed x))
(defun i= (&optional arg)
"Set string-at-point to =string-at-point=
Used in org-mode. For arbitrary content, select them first"
(interactive "P")
(dove-org-babel-shortcut "=" arg))
(defun i* (&optional arg)
"Set string-at-point to *string-at-point*
Used in org-mode. For arbitrary content, select them first"
(interactive "P")
(dove-org-babel-shortcut "*" arg))
(defun i: (&optional arg)
"Insert ': ' at each line of code
Used in org-mode. For operating on multiple lines, use prefix argument"
(interactive "P")
(beginning-of-line )
(insert ": ")
(if arg
(dotimes (i (- arg 1))
(progn
(beginning-of-line 2)
(insert ": ")))))
; (cond
; ((and mark-active transient-mark-mode)
; (i-babel-quote-str St Ed "="))
; (t
; (let ((St (and (beginning-of-string) (point)))
; (Ed (and (end-of-string) (point))))
; (i-babel-quote-str St Ed "="))))
;)
; (cond
; ((and mark-active transient-mark-mode)
; (i-babel-quote-str St Ed "*"))
; (t
; (let ((St (and (beginning-of-string) (point)))
; (Ed (and (end-of-string) (point))))
; (i-babel-quote-str St Ed "*"))))
;)
(defun action-to-list (action lst)
"Perform action to each element in the list"
(mapcar (lambda(ext) (funcall action ext)) lst))
;(defun require-extensions (action lst)
; ""
; (mapcar (lambda(ext) "" (funcall action ext)) lst))
(defun set-key-bindings (action bindingList)
""
(mapcar (lambda(lst)
""
(let ((x (car lst))
(y (car (last lst))))
(funcall action x y))) bindingList ))
(defun set-outline-minor-mode-regexp ()
""
(outline-minor-mode 1)
(let ((regexp-list (append outline-minor-mode-list nil))
(find-regexp
(lambda (lst)
""
(let ((innerList (car lst)))
(if innerList
(if (string= (car innerList) major-mode)
(car (cdr innerList))
(progn (pop lst)
(funcall find-regexp lst))))
))))
(make-local-variable 'outline-regexp)
(setq outline-regexp (funcall find-regexp regexp-list)))
(set-key-bindings 'local-set-key
(list
(list (kbd "C-c C-t") 'hide-body)
(list (kbd "C-c C-a") 'show-all)
(list (kbd "C-c C-e") 'show-entry))))
(defun hs-hide-all-comments ()
"Find all comments in the file and hide them via hs-hide-comment-region"
(interactive)
(goto-char (point-min))
(while (re-search-forward "^[ \t]*#." (point-max) 3 )
(let ((beg (line-beginning-position))
(count 1)
(end nil))
(forward-line)
(while (re-search-forward "^[ \t]*#." (line-end-position) 3 1)
(setq count (+ count 1))
(forward-line)
(setq end (line-end-position)))
(if (> count 1)
(hs-hide-comment-region beg end))
(forward-line count))))
(defun goto-symbol (arg &optional flag)
"find the next function definition"
(interactive)
(if (or flag nil)
(re-search-backward (eval arg) )
(re-search-forward (eval arg) )))
(defun find-file-and-goto-line (&optional arg)
"find a file and goto specific line
\(find-file-and-goto-line '/home/dove/org/rubykoans/koans/about_hashes.rb:8'\)
will open about_hashes.rb and goto line 8"
(interactive)
(let* ((file-name (buffer-substring-no-properties
(beginning-of-string)
(end-of-string)))
(lst (split-string file-name ":" t))
; (let* ((lst (split-string file-name "[:]" t))
(f (pop lst))
(l (string-to-number (pop lst))))
(message "file is %s line is %d" f l )
(if (file-exists-p f)
(progn
(find-file f)
(if (numberp l)
(forward-line (1- l)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun sdcv (&optional arg)
"sdcv dictionary plugin"
(interactive "P")
(shell-command (concat "sdcv " (current-word nil nil))))
(defun delete-window-next ()
"Delete window next to this one"
(interactive)
(other-window 1)
(delete-window))
(defun toggle-goagent ()
"Toggle GoAgent for W3M"
(interactive "P")
(if (or w3m-command-arguments nil)
(setq w3m-command-arguments
'("-o" "http_proxy=http://127.0.0.1:8087/"))
(setq w3m-command-arguments nil)))
(defun dove-text-to-url (&optional arg)
"Convert text to orgmode url and also fetch web page from MSDN
You would highlight the text string to be converted, such as something like this:
\\[125]PowerShell.exe Command-Line Help' which would be modified into org file link:
\\[\\[file:PowerShell.exe Command-Line Help.org][[125]PowerShell.exe Command-Line Help]]
Then the function would ask for a URL, the web page located at the URL would be fetched
and dumped into a local file named as 'PowerShell.exe Command-Line Help.org"
(interactive "P")
(let ((my-point nil) (my-string nil))
(if (and mark-active transient-mark-mode)
(let* ((st (min (mark) (point)))
(ed (max (mark) (point))))
(kill-region st ed))
(kill-region (beginning-of-string "\\]") (end-of-string)))
(setq my-string (car kill-ring))
(re-search-backward "\\[[0-9]+\\]" (line-beginning-position) 3 1)
(replace-match "")
(insert (concat "[[file:" my-string ".org][" my-string "]]"))
(let ((url-str (read-from-minibuffer "Input URL: " nil nil nil)) ; read url here
(dir (file-name-directory (buffer-file-name))))
(if (and (stringp url-str) (string-match "^http" url-str))
(progn