Table of Contents
- 1. Emacs on Microsoft Windows
- 1.2. Getting Emacs and Useful tools
- 1.3. Useful Tweaking
- 1.6. Shells
- 1.7. Visual C++ MSVC Building Tools
VS Dark Theme for GNU Emacs.Screenshots, source code and additional information. Emacs Themes. This project provides Emacs key bindings for Visual Studio users, through a Visual Studio Extension. This capability was available in VS2008, but was removed in VS2010 and VS2012. Emulation was released as a Visual Studio Extension called the 'Emacs Emulation' extension.Since the extension has not been supported by the Visual Studio Team since 2010, I was able to make the. When Visual Studio 2010 originally shipped, this feature was omitted, until recently, when much too my surprise a new Visual Studio Gallery features was created to support Emacs-mode emulation. By having this feature, I was hooked and upgrading was the next order of business.
Compare GNU Emacs vs Microsoft Visual Studio Code. 336 verified user reviews and ratings of features, pros, cons, pricing, support and more. Plus now I know LISP - currently my favorite language, much more pleasant than C or Python/Ruby/JavaScript. What are the best editors or IDEs for Perl.
Top1 Emacs on Microsoft Windows
1.1 Overview
Why Emacs on Windows ?
Emacs provides many useful tools for Windows developers or anyone thathave to use Windows for professional reasons or use Windows at worksuch as:
- Powerful terminal emulator: Emacs can be a powerful terminalemulator for Windows and a outstanding replacement for cmd.exeterminal emulator because it has history, multi line history andmulti line input and tiling windows where it is possible to splitthe Emacs window and run a repl and edit a file on the samewindow. Unlike cmd.exe Emacs can also run multiple REPLs in thesame window.
- Run any shell: Emacs can run any shell application like Python,IPython, Powershell, cmd.exe, bash, C# shell, F# and so on.
- Eshell: Eshell is unix-like shell implemented in Elisp providingmany unix commands like ls, mv, cp, rm without any externaldependencies and it is also highly integrated to Emacs allowing theuser to call elisp functions, browser directories, open files(visit buffer).
- Dired mode: Dired mode allows fast directory navigation and torun commands or apply shell commands on files like md5sum, rm -rf,git add and so on.
1.2 Getting Emacs and Useful tools
1.2.1 Getting Emacs
Emacs 32 bits
Emacs 64 bits - 64-Bit GNU Emacs for MS Windows with optimization.
Install using Chocolately Package Manager
Emacs 64 bits unnoficial
1.2.2 Getting Unix utilities
Git for Windows provides many Unix utilities ported for Windows likeawk, cat, ls, chown, grep, find and etc.
GNU Make is an useful build-automation tool and can be got from:
1.3 Useful Tweaking
1.3.1 Setting Environments Variables
- Set HOME
The HOME environment variable that has the default value/home/<username>) on Linux sets the user's directory path.
This variable, which is equivalent to _%USERPROFILE% _(
C:Users<username>
) is expected to be set by many Unix applications ported to Windows and italso makes directory browser in Emacs and shells easier.It can be set permanently by using the commmand below on cmd.exe shell.
To test if the variable is set. Open a new cmd.exe shell and type:
It allows to browser Windows directories as:
~ C:Usersarch ~/Desktop C:UsersarchDocuments ~/.emacs.d C:Usersarch.emacs.d It also allows the commands:
To open file ~/.emac.d/init.el (C:Usersarch.emacs.dinit.el)
- C-x C-f find-file ~/.emac.d/init.el
To open directory (C:UsersarchDesktop)
- C-x C-d ~/Desktop
- Set PATH
Executables located in directories listed in PATH environment variablecan be invoked without its full path like ls, echo and who inUnix-like OS or ipconfig, arp and whoami in Windows.
By adding the directory ~/bin or C:Users<user>bin to PATH variableit makes easir to call command line applications from this directorywithout specifing its full path from Emacs or shell (cmd.exe). It canbe done with:
- Add the directory C:Users<user>bin to %PATH% enviroment variable:
It makes easeir to call C:Users<user>bincurl.exe from anydirectory. Instead of write its full path the user can just run
$curl.exe
or$ curl
.
Visual Studio Emacs Emulation
1.3.2 Invert Control and Capslock
The Ctrl (Control) key is one of the most used keys, although it isone of the most inconvenient and ergonomically bad key to typepossible leading to strain injury when used often as in Emacs. On theother hand, Capslock while in a convenient position is one of the mostuseless keys as it is not used often and upper case letters can betyped just by holding the shift key while typing the underlyingletter. Those problems can be overcome by mapping the Capslock key toCtrl and Ctrl to Capslock. On Windows it can be done by running thecommands below in the powershell as administrator and then rebooting orby entering in the cmd.exe shell and typing $ powershell and thenpasting the mentioned commands.
- Source: Map capslock to ctrl - Stack Overflow
1.3.3 Initialization - init.el file.
This section provides a minimal configuration for Windows to deal withpitfalls and annoyances.
- Suppress startup screen
- Suppress Windows annoying beep or bell - Visible bell
- Do not open file or user dialog.
- Use Unix's
n
(LF- Line Feed) and utf instead of Windowsrn
(CRLF - Carriage Return and Line Feed) as end of line character. Itmay not be desirable if most files or project edited are forWindows or building tools that may fail if the source file doens'tCRLF as line ending.
- UTF8 Everywhere
- Separate Customization file from init.el
- Handy key bindings for invoking compilation command.
- Type F9 to call M-x compile
- Type Ctrl + F9 to call M-x recompile - running the compilationcommand again.
1.4 Unix utilities
You can bash install with Chocolately package manager or download GITversion control app that comes bundled with bash and Unix utilitieslike grep, mv, ssh, df and dd.
Command to run Bash. Usage: M-x run-bash
Command to run cmd.exe. Usage: M-x run-cmdexe
1.5 Environment Variables in Emacs
To run Unix utilities and other command lines apps in Emacs add to thePATH system environment variable the path to their directories like this:
1.6 Shells
1.6.1 Eshell
- Overview
Eshell provides many benefits to Windows users:
- Many unix like commands implemented on Emacs' Lisp like: mv, cp, which …
- Completion
- History: C-c C-l
- Easy copy and paste unlike cmd.exe
- Integration with Eamcs since it can run Emacs commands (interactivefunctions) like shell commands.
- Screenshots
- Demonstrations
- Commands and history
To open the history type: C-c C-l
- Emacs Integration
Eshell can run Emacs elisp commands (interactive functions) likefind-file, dired as ordinary shell commands like is shown above.
The function find-file can be executed in eshell as shell command
find-file ~/.emacs.d/init.el
.Some useful Elisp commands on Eshell:
Open file:
- find-file
- find-file-other-window
- find-file-other-frame
Open directory:
- dired
- dired-other-window
- dired-other-frame
- Asyncrhonous Commands
- Copy command output to clibpoard
Eshell comes with a pseudo clipboard device /dev/kill that is usefulto handle clipboard.
Copy command output to clibpboard
Show clibpoard content
- Shell Commands mixed with Emacs commands
Note: split-string Is an Emacs function.
Example 1:
Exmaple 2:
Example 3:
- Commands and history
1.6.2 Powershell
This command runs Powershell on Emacs:
Usage: M-x run-powershell.
1.7 Visual C++ MSVC Building Tools
1.7.1 Calling MSVC tools from Emacs
Calling the default and official Windows' C++ compiler MSVC (MicrosoftVisual C++) from command line is not easy as calling gcc, mingw orclang as MSVC needs environment variables INCLUDE, LIB, LIBPATH andPATH to be properly set with correct paths. Those settings depends onthe version of the compiler and the building target x86 (32 bits) orx64 (64 bits), so the path settings of MSVC 2015 are different fromMSVC 2017. This section provides useful commands that solve thisproblem by allowing the user call the compiler directly which may beuseful for studying c++ on Windows, learning about Windows API, testingthe compiler, building simple C++ programs or creatingproof-of-concepts.
Note: It was tested with MSVC 2017 and Windows10.
To use it just copy the functions to the file ~/.init.el or emacsintialization file.
- Porgram:
Saves the original PATH variable
This command sets environments variables for MSVC - 2017 Building tools and x68building target. If the user runs M-x msbuild-2017-x86-setup, it willallows to call the msvc compiler cl.exe with M-x compile cl.exe file.cpp. Then, the code will be compiled for x86 target. It is also possible tocall with M-x compile the commands msbuild.exe, link.exe (MSVC's linker) and dumpbin.exe (similar to GNU objdump).
The command below sets enviroment variable for MSVC - 2017 and x64building target and its similar to msbuild-2017-x86-setup.
This command allows to compile the current buffer. For instance, ifthe current buffer is associated to a file test1.cpp and user typesM-x compile-msvc-x86, it will show a prompt with cl.exe test1.cppasking the user to confirm or complement the compilation command.
The screenshot below shows an example about how those commands can beused:
Test file: codes/test.cpp
1.7.2 Commands for MSVC2015
M-x msbuild-2015-x86-setup and Set environment variables to allowcalling cl.exe for x86 build target and other tools from M-xcompile and shell commands.
M-x msbuild-215-x64-setup - Similar to previous command.
Commands to compile file related to current c++ buffer.
1.7.3 Install C++ Compilers and MSVC Building Tools
The esiest and fastest way to install MSVC building tools is by usingthe chocolately package manager which provides a Linux-like experiencefor installing packages.
Visual Studio Emacs Shortcuts
Install Visual C++ Build Tools 2015 14.0.25420.1
Install Visual Studio 2017 Build Tools 15.2.26430.20170650
Install Mingw - gcc/g++ GNU C/C++ Compiler ported for Windows
1.7.4 Build automation tools and batch files
Batch files (*.bat extensions) can be used as *nix Makefiles toperform build-automation on Windows, compile C++, C, and C# programsand also perform a wide variety of tasks.
Example: This file build.bat compiles and run the file test1.cpp withVisual C++ compiler. To build the C++ file codes/test.cpp, itjust to put this file to the directory to the directory where istest.cpp and then type in Emacs M-x build or M-x build.bat.
The build script can also be executed using the Windows shell cmd.exe,by entering $ cd <project> and then typing build or build.bat. It canalso be run by double clicking at the file build.bat.
File: codes/build.bat
This build script can be adapted to use other Windows building tools,for instance, the line where is cl.exe could be replaced with:
- $ msbuild WpfAppLearning.sln /p:Configuration=Release /p:Platform='Any CPU'
- To build a Visual studio solution (aka project).
- $ Devenv WpfAppLearning.sln /Rebuild Debug
- Rebuild applicatio with Visual Studio Command line switch.
- $ fsc.exe app1.fsx <flags>
- Compile a F# application
- $ csc.exe app1.cs
- Compile a C# application
- $ scalac app1.scala -d app1.jar && scala app1.jar
- Compile a Scala application and run it.
It is also worth knowing some DOS / Windows command line tools forcompiling applications on Windows.
Description | Unix, Linux, MacOSX and BSD | Windows, MSDOS and OS/2 |
---|---|---|
Show Command Help | bash –help | set /?, cl.exe /? .. |
Show current User | whoami | whoami |
Show path of application or executable | which bash | where notepad.exe |
Clear terminal | clear | cls |
Go to directory, aka path | cd <path>; | cd <path> |
Go to Disk or Mount Point | $ cd /mnt/mount-point | $ C:, $ D:, $ E: .. |
Change to a different directory | cd | cd |
List directory | ls <dir> | dir <dir> |
List file directory in chronological order with detail | ls -ltr | dir /od |
Make a new directory | mkdir | mkdir or md |
Delete a directory | rmdir | rmdir or rd |
Display contents of a text file | cat <file> | type <file> |
Copy a file, preserving its date-time stamp | cp -p | copy <file> <dest> |
Delete a file | rm <file> | erase <file> OR del <file> |
Move a file | mv <file> <new-name> | move |
Rename a file | mv | ren |
Find a file | find | dir /s |
Grep a file | grep | findstr |
Display differences between two text files | diff | fc |
Change file attributes | chmod | attrib |
“Super-user” root authorization | sudo | N/A |
Create symbolic link to a file or directory | ln | N/A |
Show environment variables | env | set |
Set environment variable | export PATH=$PATH:/dir/bin | set PATH=%PATH%;E:/dir/bin |
Set environment variable permanently | N/A | setx <VARIABLE>=<VALUE> |
Redirect command output to file | set | |
Open file dor directory with default system application | xdg-open file1.ppt | start file1.ppt |
Shrink executable file size | strip | strip (included w/ Free Pascal) |
- Note:
- xdg-open only exists on Linux or BSD with X11
- On MacOSX the equivalent is open