= About me =

I use Emacs.

This is some Emacs extensive functions I wrote in my daily work.

Lisp:dove-ext.el

= Describe the code now =

== Copy without selection ==

=== copy-line ===

Copy lines at point and paste them to mark

With prefix 1, copy but not paste.
with prefix N, copy N lines from the point.

=== copy-word ===

Copy words at point and paste them to mark

With prefix 1, copy but not paste.

with prefix N, copy N words from the point.

=== copy-paragraph ===

Copy paragraphs at point and paste them to mark

With prefix 1, copy but not paste.

with prefix N, copy N paragraphs from the point.

=== thing-copy-string-to-mark ===

Copy string at point or region selected and paste them to mark

With prefix 1, copy but not paste.

with prefix N, copy N strings from the point.

=== thing-copy-parenthesis-to-mark ===

Copy region between {[(<"\'\'">)]\} and paste them to mark

Automatic due with nesting {[(<"\'\'">)]} characters

=== duplicate-line ===

Duplicate current line.

Used for temporary comment out line of code and replace it with something else.

== Window splite/rotate functions ==

=== split-window-4 ===

This function splits frame into 4 windows, like following.
{{{
  +-----------------------+----------------------+
  |                       |                      |
  |                       |                      |
  |                       |                      |
  +-----------------------+----------------------+
  |                       |                      |
  |                       |                      |
  |                       |                      |
  +-----------------------+----------------------+
}}}

I used to run shell mode in these windows.


=== change-split-type ===

Change split type in both 2 windows & 3 windows are rewritten. Everything is based on a common function {{ change-split-type }}.

{{{

  (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)))

}}}

=== change split type in 2 windows mode ===

Then I can implement {{ change-split-type-2 }} from it, which could rotate window splitting from
vertically to horizontally and vice-versa.

{{{

                             change-split-type-2  -->

  +------------------------+                  +----------+-----------+
  |                        |            \     |          |           |
  |                        |    +-------+\    |          |           |
  +------------------------+    +-------+/    |          |           |
  |                        |            /     |          |           |
  |                        |                  |          |           |
  +------------------------+                  +----------+-----------+

                     <--  M-1 change-split-type-2
  +----------- +-----------+                  +----------------------+
  |            |           |            \     |                      |
  |            |           |    +-------+\    |                      |
  |            |           |    +-------+/    +----------------------+
  |            |           |            /     |                      |
  |            |           |                  |                      |
  +----------- +-----------+                  +----------------------+

  (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)))


}}}


=== change split type in 3 windows mode ===

Change split type in 3 windows mode is more interesting now. You can change split type to vertical
from anytime and exchange from 2 vertical types with a numeric prefix.

{{{

                             change-split-type-3-v -->

   +----------- +-----------+                   +----------- +-----------+
   |            |           |     /       \     |            |           |
   |            |           |    /+-------+\    |            |           |
   |------------|           |    \+-------+/    |            |-----------|
   |            |           |     \       /     |            |           |
   |            |           |                   |            |           |
   +----------- +-----------+                   +----------- +-----------+

                 <--  M-1 change-split-type-3-v


  (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))
                                                                           
}}}                                                                        
                                                                           
Same condition comes to horizontal mode.                                                                           
                                                                                                         
{{{

                             change-split-type-3-h  -->                                                                                     
                                                                                                      
   +-----------------------+                   +-----------------------+
   |           |           |    /       \      |                       |
   |           |           |   /+-------+\     |                       |
   +-----------------------+   \+-------+/     +-----------------------+
   |                       |    \       /      |           |           |
   |                       |                   |           |           |
   +-----------------------+                   +-----------------------+

                 <--  M-1 change-split-type-3-h


  (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))

}}}


=== roll-3-buffers-clockwise ===

Roll 3 window buffers clockwise with windows split type unchanged

=== roll-3-buffers-anti-clockwise ===

Roll 3 window buffers anti-clockwise with windows split type unchanged


{{{
  +----------- +-----------+                    +----------- +-----------+
  |            |     C     |            \       |            |     A     |
  |            |           |    +-------+\      |            |           |
  |     A      |-----------|    +-------+/      |     B      |-----------|
  |            |     B     |            /       |            |     C     |
  |            |           |                    |            |           |
  +----------- +-----------+                    +----------- +-----------+

  +------------------------+                    +------------------------+
  |           A            |            \       |           B            |
  |                        |    +-------+\      |                        |
  +------------------------+    +-------+/      +------------------------+
  |     B     |     C      |            /       |     C     |     A      |
  |           |            |                    |           |            |
  +------------------------+                    +------------------------+

}}}

[new]
Latest updates about these functions could be found in ThreeWindows

== Shell-mode related functions ==

=== exitshell ===

Exit from recursive shell logins automatically.

=== rename-buffer-in-ssh-login ===

Rename buffer to the destination hostname in ssh login

=== kill-shell-buffer-after-exit ===

Kill shell buffer after exit from shell process.

=== rename-buffer-in-ssh-login ===

Rename buffer to the destination hostname in ssh login

Since I used to login to a lot of different machines in my daily work, I'd like to have the shell buffer name to represent the hostname of which I am working on.

=== rename-buffer-in-ssh-exit ===

Rename buffer to its previous name when user exit from a ssh login.

I do not just login to the destination machine from my GNU Emacs. Instead I used to login to a central host first, and then to login to any destinations from there.

So I need to have the shell buffer changes accordingly when I exit from a destination host and back to the central one.

**This function is still in its babyhood. It could only work well in a single shell session. I am not sure how to handle multiple shell sessions simultaneously. And exit from a subshell is also a problem.**

**If anyone has good ideas, its warm welcome here!.**

<pre>
--8<-------------------------- §separator§ ------------------------>8--
,-----------
|    DennyZhang:
|    If you are meaning invoke multiple shells, we basically
|    have two ways: Ctrl+u Alt+x shell, or (shell shell-buffer-name).
|
|    You can check below for detail.
|        http://www.emacswiki.org/emacs/ShellMode#toc3
|        EmacsWiki: Shell Mode
|        http://mjtsai.com/blog/2003/01/02/multiple_emacs_shell_buff/
|        Michael Tsai - Blog - Multiple Emacs Shell Buffers
|
|    Hi David, I have implemented bunches of lisp functions, which
|    serves as a handy shell extension. I use it everyday. Maybe you
|    can have a look.
|    http://hi.baidu.com/filebat/blog/item/262915d12a3299cf562c8481.html
`-----------
</pre>

Yes. It is the native way. But a host name is more meaningful than a sequence number.  A similar problem occurs when find two files with the same name from different directories.  It would be more meaningful to attach a parent directory name as prefix in the buffer name than to attach a sequence number. But I didn't have time to make it.

=== kill-shell-buffer-after-exit ===

Kill shell buffer after user exited from shell.

It is very ugly that the shell buffer will keep exist even user has already been exited from it. So I wrote this function to kill it for me.

I chose to use 'set-process-sentinel' function instead of monitor user commands. 'set-process-sentinel' is provided by shell mode itself. So it makes things simpler.

=== shell-args ===

It makes you be able to refer to some messages from the ouput of your previous command. It is quite similar with what you do with history(!), but refer to the outputs instead of commands

{{{

   ;; suppose you have in this situation in shell-mode, 
   
   2 + 21:51:40 + ~/Shell/branch_dev
   ➜   svn status | egrep '^[^?]'
   svn status | egrep '^[^?]'
   M       setup_env_tivx09/Windows/win-bashrc
   M       testware/easyBroker.win.pl
   
   3 + 21:51:44 + ~/Shell/branch_dev
   ➜   

   ;; how could you get a command like this without any redundent operation?
   3 + 21:51:44 + ~/Shell/branch_dev
   ➜   svn diff testware/easyBroker.win.pl

   ;; See, you can type this command and then M-x shell-args
   3 + 21:51:44 + ~/Shell/branch_dev
   ➜   svn diff #1:2

   ;; Then it turns out
   3 + 21:51:44 + ~/Shell/branch_dev
   ➜   svn diff testware/easyBroker.win.pl

   ;; Kind of cool? You can also do replacement, just like in a !
   3 + 21:51:44 + ~/Shell/branch_dev
   ➜   svn diff #1:2:s/win/linux/

   ;; Then you can get this
   3 + 21:51:44 + ~/Shell/branch_dev
   ➜   svn diff testware/easyBroker.linux.pl

   ;; Cool!

}}}

== Org-mode related functions ==

=== isrc ===

Enclose code for org-mode

{{{
#+begin_src
some
source code
#+end_src
}}}

=== iexp ===

Enclose example for org-mode

{{{
#+BEGIN_EXAMPLE
some
examples
#+END_EXAMPLE
}}}

=== ihtml ===

Enclose code for Emacser.cn

{{{
#+BEGIN_HTML
<pre lang="lisp" line="1">
some
content
</pre>
#+END_HTML
}}}


=== isrc-para ===

Like isrc but enclose code at point for org-mode


=== iexp-para ===

Like iexp but enclose code at point for org-mode


=== i(equal sign) ===

Set string-at-point to =string-at-point=

Used in org-mode. For arbitrary content, select them first

=== i* ===

Set string-at-point to *string-at-point*

Used in org-mode. For arbitrary content, select them first

=== i: ===

Insert ': ' at each line of code

Used in org-mode. For operating on multiple lines, use prefix argument

== Arbitrary functions ==

=== matrixSum ===

Calculate matrix statistics by row & column. Then insert result into current buffer.
Calculation is doing from a predefined shell script named as 'matrixSum'

=== come-here ===

Bring content from specific buffer to current buffer.

=== jump ===

Take the command at point, jump to another window, then paste it at prompt.

If the destination window is not in shell-mode, just paste it to the point over there. This makes jump useful in other text edit modes.


=== some ===

Delete all output from interpreter since the one before the last input. Because comint-delete-output just could not do it for you.


=== my-overwrite ===

When overwrite-mode is on, display a red alert at the beginning of mode line. When overwrite-mode is off, remove the alert.


= Discussion =

[new:DrewAdams:2010-07-31 15:41 UTC]
Welcome to the wiki. -- DrewAdams

[new:DavidYoung:2010-07-31 15:48 UTC]
Thanks for your kind greeting. You're so fast. BTW, can you advise me how to make the Lisp:dove-ext.el page becomes a download-able lisp file? I tried many times but always fail. -- DavidYoung

[new:DrewAdams:2010-07-31 16:34 UTC]
Looks to me like you succeeded. -- DrewAdams

[new]
I succeed when I pasted lisp code on the page directly, instead of replace that page with code file.  -- DavidYoung

[new:DrewAdams:2010-08-01 14:01 UTC]
Right. -- DrewAdams


----
CategoryHomepage
