Zur deutschen Version.
I had started to use EMACS occasionally with version 20.7. Since 2016-11 I am using EMACS 25.1 and have been using it regularely. This folder contains documents where I share information about
The EMACS documentation, both built into EMACS and available online, is very complete and detailed. However I found myself jotting down things while I learned. I share these below. These might be useful to people who have similar requirements.
I appreciate EMACS supports well classical terminal operation by providing "windows" functionality. However I am using EMACS from a MS Windows desktop and I am used to working with native windows there, which are called "frames" in EMACS.
I have customised (download my init.el) EMACS such that it uses
"frames" by default (for example when it opens a *help*
window for
you).
'(pop-up-frames (quote graphic-only))
C-x C-+
increase font site, repeat C-+
for more. Only affects current buffer
C-x C--
decrease font size
C-x C-0
go back to standard font size
C-space C-space
sets a mark and clears it again.
C-x C-x
(exchange-point-and-mark) brings you back where you set
the mark.
C-x r SPC r
saves to cursor position in "register" r
(one letter)
C-x r j r
jumps back
Registers are volatile. Bookmarks are being saved.
In EMACS a paragraph is terminated by an empty line.
M-q
"fill paragraph" aligns every line in a paragraph, breaking
lines that are too long. The variable fill-column
governs how long
the lines are, the length defaults to 70 characters (more precisely:
default right margin: 70).
However, to set the variable comment-auto-fill-only-comments
to
non-nil did not have the effect, to align automatically ;;;
assembly language comments.
M-x occur
shows all lines in a buffer that contain the search string. They are shown in a separate frame/window, with hyperlinks you can follow/click. However, this works for one buffer only.
What M-x occur-mode
does, I still need to understand.
M-x hexl-mode
Often I need a serial terminal app. to connect to a microcontroller via RS232 for debug purposes. As I use Windows, there is no out-of-the box app. ever since Hyperterm was not any more delivered with Windows. Fortunately such functionality is built into EMACS and can be activated via
M-x serial-terminal
See http://www.gnu.org/software/emacs/manual/html_node/emacs/Serial-Terminal.html
Tools > Search Files (grep) ...
, and input
grep -nH -r --include='*.org' regexp .
This will search recursively (-r
) in all files with extension org
for the string regexp
. The -n
option brings clickable links in the
buffer, which contains the grep
ouput. In my EMACS installation, the
command grep -nH
would appear in the minibuffer, when I select the
menu item. I complete the rest manually.
Find files, that do not contain a string
grep -nH -r -L --include='*.org' string .
Under Linux, grep
in EMACS will work out of the box. Under Windows,
I needed to include git
for Windows, for tools like bash
and
grep
to be available in EMACS. In addition, I had to tweak the
configuration in init.el
to make sure grep
does not complain about
the "empty directory issue".
The same menu item like above, Tools > Search Files (grep) ...
, can
be used to search for files:
find . -name 'body*.org'
This will find all files which start with body
and have the
extension .org
. To ignore the file name case, you write
find . -iname 'body*.org'
Find directories, that do not contain a specific file:
find . -type d '!' -exec test -e "{}/xyz.ext" ';' -print
Note that find
does not have a -n
option that would produce an
output buffer with links. But you can manually copy/paste the results
of course.
Just to be clear: to use find
, I manually overtyped the grep -nh
string in the minibuffer with the find command. If there is a simpler
way, please tell me.
If you have a file open in a buffer (which sets the current directory) and then do
M-x tags-search
then EMACS tries to open a so called TAGS file in that directory. If the TAGS file is not in the same directory, then you could supply a relative or absolute path. Then EMACS asks you a search pattern.
M-,
looks for the next hit until all files have been processed.
Similarly
M-x tags-query-replace
does a query and replace.
To change the TAGS file that is being used, use
M-x visit-tags-table
The current directory can be changed in Menu, Files, Open Directory...
.
The path separator seems to be /
even under Windows.
To use the EMACS "TAGS" feature, you first got to generate a TAGS file specific to the project you are working. One possible procedure:
myGenTAGS.cmd
The script consists of two lines:
TYPE flist.txt | C:\Users\xyz\OneDrive\myPrograms\emacs-25.1\bin\etags.exe - PAUSE
This will generate the file "TAGS" in the same directory. Replace the path above with the path where you installed EMACS (see my approach under Windows).
To search for or replace something with newline, input C-q C-j
.
C-q
is the "quote" character, that tells EMACS, that the following
character shall be taken literally. C-j
is the ASCII code for
newline. Similarely, C-m
is the ASCII code for carriage return.
C-i
is the ASCII code for Tab. Tab
instead of C-i
should also
work.
By default search regexp treats upper and lower case the same. This is
set by the variable tags-case-fold-search
See https://www.gnu.org/software/emacs/manual/html_node/emacs/Identifier-Search.html
In older EMACS versions, e.g. 20.7, tags-case-fold-search
was not
existing, only case-fold-search
, but it seemed to have the same
effect.
Use the search regexp
[[:nonascii:]]
The cursor will be set past the found character.
If you want to search multiple files in one or more specific directories, then dired is quite appropriate.
The following examples are source code changes. They also work with
M-x tags-query-replace
To change
xyz_Q_OFFS
or xyz_D_OFFS
to
Q_xyz_OFFS
respectively D_xyz_OFFS
Query regexp:
\([A-Z0-9]+\)_\([DQ]\)_OFFS
Replace expression:
\2_\1_OFFS
From
aOutVol
to
MA_A_OutVol
Q:
\(\s-\)a\([A-Z][a-zA-Z0-9]+\)
R:
\1MA_A_\2
From e.g.
EB_VolAttOsc1_OFFS
to
EB_VOLATTOSC1_OFFS
i.e. to upper case
Q:
\(EB_\)\([A-Z][a-zA-Z0-9]+\)\(_OFFS\)
R:
\1\,(upcase \2)\3
Similarly: downcase
Q:
abc[ ]efg
To change
abc_efg\w
to
(abd_efg).w
Query regexp
\([a-zA-Z0-9_]+\)\\w
Replace expression
(\1).w
; one or twice or three-times according to hierarchy level.
M-j
new line in a comment
M-;
insert or re-align comment
To switch on a powerfull mode to compare files do
M-x ediff
I wanted to have the two files side by side rather than one on top of
each other. So C-h v ediff-split-window-function
and "customize"
this variable. The default is "Split vertically" which I changed to
"Split horizontally" then "Apply and Save". What happened in my case,
that two frames where created. I can avoid this by creating two
windows before, side by side.
M-x ediff-revision
allows to compare two file revisions.
Alt+x eww
The most useful keys
p
eww-previous-url
r
eww-forward-url
&
eww-browse-with-external-browser
g
eww-reload
w
eww-copy-page-url
v
eww-view-source
Alt+x
eww again.
Alt+x eww-open-file
Alt+x eww-browse-with-external-browser [&]
M-x set-buffer-file-coding-system
then: unix
or dos
or mac
I should also try C-x RET f
C-x SPC
then size the rectangle using the cursor keys, then C-c
Open the file and then indent it by indenting the entire region:
M-x find-file /path/to/file RET
C-x h
(M-x mark-whole-buffer
)
C-M-\
(M-x indent-region
)
VC is enabled automatically whenever you visit a file governed by a
version control system. To disable VC entirely, set the customisable
variable vc-handled-backends
to nil (see Customizing VC).
See https://www.gnu.org/software/emacs/manual/html_mono/emacs.html
Use
M-x auto-revert-mode
See http://www.gnu.org/software/emacs/manual/html_mono/efaq-w32.html
Change language using
M-x ispell-change-dictionary
(M-x isp-c-d
will also do), then e.g. "deutsch"
If EMACS heuristics fails, which tries to guess a file's encoding, do:
C-x RET r
or M-x revert-buffer-with-coding-system
See (info "(emacs) Specify Coding") for details.
init.el
AgainM-: (load user-init-file)
M-x eval-buffer
Either put in the *scratch*
buffer
(require 'xyz)
or do
M-x lisp-interaction-mode
C-c <letter>
is explicitely reserved for the user and no mode should
claim them. Also C-<number>
or <M-<number>
seem to be available.
"Hack EMACS" Rick Dillon on Youtube
Xah Lee's EMACS site http://ergoemacs.org/
Chris Wellons' articles about EMACS https://nullprogram.com/tags/emacs/ for example about EMACS' handling of the "working directory" versus Vim's: https://nullprogram.com/blog/2017/08/22/
"Publishing a book using org-mode" from Lakshmi Narasimhan https://medium.com/@lakshminp/publishing-a-book-using-org-mode-9e817a56d144
Emacs org-mode examples and cookbook http://ehneilsen.net/notebook/orgExamples/org-examples.html