spacemacs, evil insert-mode jump to the beginning of the line - spacemacs

I try to jump to the beginning/end of the line, and when I am in vim, I write the following code:
inoremap <leader>a <Home>
inoremap <leader>e <End>
and it works fine. However, when I am in spacemacs, I do this:
(define-key evil-insert-state-map ",a" 'beginning-of-line)
(define-key evil-insert-state-map ",e" 'end-of-line)
everything goes right except that I can't type comma anymore (I mean, when I type "," it just waits there). Here is the message when I type comma:
a -> beginning-of-line e -> end-of-line
PS. I am working on Ubuntu 18.02 LTS with GNU Emacs 25.2.2
(I am new to spacemacs and know little about elisp)

It seems this works fine:
(define-key evil-insert-state-map (kbd "C-a") 'beginning-of-line)
(define-key evil-insert-state-map (kbd "C-e") 'end-of-line)
(define-key evil-insert-state-map (kbd "C-n") 'next-line)
(define-key evil-insert-state-map (kbd "C-p") 'previous-line)

Related

neovim is transparent but the auto copplete window is pink.how to make it semi transparent (black) too?

i use parrot security as my daily distro. its mate terminal is transparent so is vim .but i wanted to get auto complete and used some plugins.auto complete window appears to be in pink which looks really ugly in semi transparent black background.i changed the theme and it was fixed but so was gone vim transparency .
in short word (1)i have to keep the default (2)i have to keep
transparent vim (3)i have to change the auto complete window from
pink to semi transparent black
here is my init.vimrc
set number
set expandtab
set autoindent
set softtabstop=4
set shiftwidth=4
set tabstop=4
"Enable mouse click for nvim
set mouse=a
"Fix cursor replacement after closing nvim
set guicursor=n-v-c-sm:block,
"Shift + Tab does inverse tab
inoremap <S-Tab> <C-d>
"See invisible characters
set list listchars=tab:>\ ,trail:+,eol:$
let $NVIM_TUI_ENABLE_CURSORE_SHAPE=1
"wrap to next line when end of line is reached
set whichwrap+=<,>,[,]
"-----------------------------------------------------------
"===========================================================
"-----------------------------------------------------------
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'scrooloose/nerdtree'
Plug 'tsony-tsonev/nerdtree-git-plugin'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
Plug 'ryanoasis/vim-devicons'
Plug 'airblade/vim-gitgutter'
Plug 'ctrlpvim/ctrlp.vim' " fuzzy find files
Plug 'scrooloose/nerdcommenter'
Plug 'christoomey/vim-tmux-navigator'
Plug 'morhetz/gruvbox'
Plug 'HerringtonDarkholme/yats.vim' " TS Syntax
Plug 'joshdick/onedark.vim'
Plug 'sheerun/vim-polyglot'
Plug 'sheerun/vim-polyglot'
" File Explorer
Plug 'scrooloose/NERDTree'
" Auto pairs for '(' '[' '{'
Plug 'jiangmiao/auto-pairs'
Plug 'http://github.com/tpope/vim-surround' " Surrounding ysw)
Plug 'https://github.com/preservim/nerdtree' " NerdTree
Plug 'https://github.com/tpope/vim-commentary' " For Commenting gcc & gc
Plug 'https://github.com/vim-airline/vim-airline' " Status bar
Plug 'https://github.com/lifepillar/pgsql.vim' " PSQL Pluging needs :SQLSetType pgsql.vim
Plug 'https://github.com/ap/vim-css-color' " CSS Color Preview
Plug 'https://github.com/rafi/awesome-vim-colorschemes' " Retro Scheme
Plug 'https://github.com/neoclide/coc.nvim' " Auto Completion
Plug 'https://github.com/ryanoasis/vim-devicons' " Developer Icons
Plug 'https://github.com/tc50cal/vim-terminal' " Vim Terminal
Plug 'https://github.com/preservim/tagbar' " Tagbar for code navigation
Plug 'https://github.com/terryma/vim-multiple-cursors' " CTRL + N for multiple cursors
call plug#end()
inoremap jk <ESC>
nmap <C-n> :NERDTreeToggle<CR>
vmap ++ <plug>NERDCommenterToggle
nmap ++ <plug>NERDCommenterToggle
" open NERDTree automatically
"autocmd StdinReadPre * let s:std_in=1
"autocmd VimEnter * NERDTree
let g:NERDTreeGitStatusWithFlags = 1
"let g:WebDevIconsUnicodeDecorateFolderNodes = 1
"let g:NERDTreeGitStatusNodeColorization = 1
"let g:NERDTreeColorMapCustom = {
"\ "Staged" : "#0ee375",
"\ "Modified" : "#d9bf91",
"\ "Renamed" : "#51C9FC",
"\ "Untracked" : "#FCE77C",
"\ "Unmerged" : "#FC51E6",
"\ "Dirty" : "#FFBD61",
"\ "Clean" : "#87939A",
"\ "Ignored" : "#808080"
"\ }
let g:NERDTreeIgnore = ['^node_modules$']
" vim-prettier
"let g:prettier#quickfix_enabled = 0
"let g:prettier#quickfix_auto_focus = 0
" prettier command for coc
command! -nargs=0 Prettier :CocCommand prettier.formatFile
" run prettier on save
"let g:prettier#autoformat = 0
"autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html PrettierAsync
" ctrlp
let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard']
" j/k will move virtual lines (lines that wrap)
noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
set relativenumber
set smarttab
set cindent
set tabstop=4
set shiftwidth=4
" always uses spaces instead of tab characters
set expandtab
" sync open file with NERDTree
" " Check if NERDTree is open or active
function! IsNERDTreeOpen()
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction
" Call NERDTreeFind iff NERDTree is active, current window contains a modifiable
" file, and we're not in vimdiff
function! SyncTree()
if &modifiable && IsNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff
NERDTreeFind
wincmd p
endif
endfunction
" Highlight currently open buffer in NERDTree
autocmd BufEnter * call SyncTree()
" coc config
let g:coc_global_extensions = [
\ 'coc-snippets',
\ 'coc-pairs',
\ 'coc-tsserver',
\ 'coc-eslint',
\ 'coc-prettier',
\ 'coc-json',
\ ]
" from readme
" if hidden is not set, TextEdit might fail.
set hidden " Some servers have issues with backup files, see #649 set nobackup set nowritebackup " Better display for messages set cmdheight=2 " You will have bad experience for diagnostic messages when it's default 4000.
" don't give |ins-completion-menu| messages.
set shortmess+=c
" always show signcolumns
set signcolumn=yes
" Use tab for trigger completion with characters ahead and navigate.
" Use command ':verbose imap <tab>' to make sure tab is not mapped by other plugin.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position.
" Coc only does snippet and additional edit on confirm.
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" Or use `complete_info` if your vim support it, like:
" inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')
" Remap for rename current word
nmap <F2> <Plug>(coc-rename)
" Remap for format selected region
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap for do codeAction of current line
nmap <leader>ac <Plug>(coc-codeaction)
" Fix autofix problem of current line
nmap <leader>qf <Plug>(coc-fix-current)
" Create mappings for function text object, requires document symbols feature of languageserver.
xmap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap if <Plug>(coc-funcobj-i)
omap af <Plug>(coc-funcobj-a)
" Use <C-d> for select selections ranges, needs server support, like: coc-tsserver, coc-python
nmap <silent> <C-d> <Plug>(coc-range-select)
xmap <silent> <C-d> <Plug>(coc-range-select)
" Use `:Format` to format current buffer
command! -nargs=0 Format :call CocAction('format')
" Use `:Fold` to fold current buffer
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" use `:OR` for organize import of current buffer
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add status line support, for integration with other plugin, checkout `:h coc-status`
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Using CocList
" Show all diagnostics
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
if (has("termguicolors"))
set termguicolors
endif
"onedark theme"
syntax on
so what should i so?
If you are using neovim there is an option called :h pumblend which can be used to change the transparency of the popup menu.
Are you sure gruvbox caused your vim to lose transparency? I am not sure if vim is able to change a terminal emulator's transparency. I or someone else might be able to advise you better if you post pictures of what has changed.

Is there a way to remove a single line from the output of Rollup?

I am looking for a way to remove the first line of the rollup output file. I know I can do it with a script and say sed, but I am looking for something a little cleaner.
I tried plugins like replace & strip but these do not seem to let me "replace" a line of code.
Does anyone how to do this? Is there a plugin?
Update
Here is my current sed solution...
"build": "rollup -c && npm run fix:rollup",
"fix:rollup": "sed '1d' ./dist/index.js > ./tmp.js; mv ./tmp.js ./dist/index.js"
Use writeBundle hook, sketch:
import fs from 'fs';//Node.js builtin
...
plugins:[
{//inline plugin
writeBundle(bundle){
for (const [fileName, chunkOrAsset] of Object.entries(bundle)) {
//test for file you want to modify
const data = fs.readFileSync(fileName, {encoding:'utf8'});
data.replace(/^[^\n]*\n/,'');
fs.writeFileSync(...)
}
}
]

Error while installation of spacemacs

I am facing the following error while trying to install spacemacs. I am presently on ubuntu 17.04.
Warning (initialization): An error occurred while loading '/home/User/.emacs.d/init.el'
File error: Searching for program, Is a directory,
Here is the error code I get while opening on --debug-init:
Debugger entered--Lisp error: (file-error "Searching for program" "Is a directory" "")
call-process("" nil t nil "-c" "/usr/bin/timeout --help")
apply(call-process "" nil t nil ("-c" "/usr/bin/timeout --help"))
process-file("" nil t nil "-c" "/usr/bin/timeout --help")
shell-command-to-string("/usr/bin/timeout --help")
(string-match-p "^ *-k" (shell-command-to-string (concat prog " --help")))
(and prog (string-match-p "^ *-k" (shell-command-to-string (concat prog " --help"))))
(if (and prog (string-match-p "^ *-k" (shell-command-to-string (concat prog " --help")))) (progn prog))
(when (and prog (string-match-p "^ *-k" (shell-command-to-string (concat prog " --help")))) prog)
(let ((prog (or (executable-find "timeout") (executable-find "gtimeout")))) (when (and prog (string-match-p "^ *-k" (shell-command-to-string (concat prog " --help")))) prog))
eval((let ((prog (or (executable-find "timeout") (executable-find "gtimeout")))) (when (and prog (string-match-p "^ *-k" (shell-command-to-string (concat prog " --help")))) prog)))
custom-initialize-reset(package-build-timeout-executable (let ((prog (or (executable-find "timeout") (executable-find "gtimeout")))) (when (and prog (string-match-p "^ *-k" (shell-command-to-string (concat prog " --help")))) prog)))
custom-declare-variable(package-build-timeout-executable (let ((prog (or (executable-find "timeout") (executable-find "gtimeout")))) (when (and prog (string-match-p "^ *-k" (shell-command-to-string (concat prog " --help")))) prog)) "Path to a GNU coreutils \"timeout\" command if available.\nThis must be a version which supports the \"-k\" option." :group package-build :type (file :must-match t))
eval-buffer(#<buffer *load*-807180> nil "/home/sujit/.emacs.d/core/libs/package-build.el" nil t) ; Reading at buffer position 3283
load-with-code-conversion("/home/sujit/.emacs.d/core/libs/package-build.el" "/home/sujit/.emacs.d/core/libs/package-build.el" nil t)
require(package-build)
eval-buffer(#<buffer *load*-522675> nil "/home/sujit/.emacs.d/core/libs/quelpa.el" nil t) ; Reading at buffer position 1420
load-with-code-conversion("/home/sujit/.emacs.d/core/libs/quelpa.el" "/home/sujit/.emacs.d/core/libs/quelpa.el" nil t)
require(quelpa)
configuration-layer//configure-quelpa()
(let ((display-buffer-alist (quote (("\\(\\*Compile-Log\\*\\)\\|\\(\\*Warnings\\*\\)" (display-buffer-in-side-window) (inhibit-same-window . t) (side . bottom) (window-height . 0.2)))))) (configuration-layer//configure-quelpa) (let* ((upkg-names (configuration-layer//get-uninstalled-packages packages)) (not-inst-count (length upkg-names)) installed-count) (if upkg-names (progn (spacemacs-buffer/set-mode-line "Installing packages...") (spacemacs//redisplay) (let ((delayed-warnings-backup delayed-warnings-list)) (spacemacs-buffer/append (format "Found %s new package(s) to install...\n" not-inst-count)) (configuration-layer/retrieve-package-archives) (setq installed-count 0) (spacemacs//redisplay) (let ((--dolist-tail-- upkg-names) pkg-name) (while --dolist-tail-- (setq pkg-name ...) (setq installed-count ...) (configuration-layer//install-package ...) (setq --dolist-tail-- ...))) (spacemacs-buffer/append "\n") (if init-file-debug nil (setq delayed-warnings-list delayed-warnings-backup)))))))
configuration-layer//install-packages((ace-jump-helm-line ace-link ace-window adaptive-wrap aggressive-indent async auto-compile auto-highlight-symbol avy bind-key bind-map clean-aindent-mode column-enforce-mode define-word desktop diminish dumb-jump elisp-slime-nav eval-sexp-fu evil evil-anzu evil-args evil-ediff evil-escape evil-exchange evil-iedit-state evil-indent-plus evil-lisp-state evil-matchit evil-mc evil-nerd-commenter evil-numbers evil-search-highlight-persist evil-surround evil-tutor evil-unimpaired evil-visual-mark-mode evil-visualstar exec-path-from-shell expand-region eyebrowse fancy-battery fill-column-indicator flx-ido golden-ratio google-translate helm helm-ag helm-descbinds helm-flx ...))
(let ((packages (append (configuration-layer/filter-objects configuration-layer--used-distant-packages (function (lambda (x) (let ... ...)))) (if (eq (quote all) dotspacemacs-install-packages) (progn (let (all-other-packages) (let ... ...) (configuration-layer//get-distant-packages all-other-packages nil))))))) (configuration-layer//install-packages packages) (if (and (or (eq (quote used) dotspacemacs-install-packages) (eq (quote used-only) dotspacemacs-install-packages)) (not configuration-layer-force-distribution) (not configuration-layer-exclude-all-layers)) (progn (configuration-layer/delete-orphan-packages packages))))
(if no-install nil (let ((packages (append (configuration-layer/filter-objects configuration-layer--used-distant-packages (function (lambda ... ...))) (if (eq (quote all) dotspacemacs-install-packages) (progn (let ... ... ...)))))) (configuration-layer//install-packages packages) (if (and (or (eq (quote used) dotspacemacs-install-packages) (eq (quote used-only) dotspacemacs-install-packages)) (not configuration-layer-force-distribution) (not configuration-layer-exclude-all-layers)) (progn (configuration-layer/delete-orphan-packages packages)))))
configuration-layer/sync()
(if (not (version<= spacemacs-emacs-min-version emacs-version)) (error (concat "Your version of Emacs (%s) is too old. " "Spacemacs requires Emacs version %s or above.") emacs-version spacemacs-emacs-min-version) (load-file (concat (file-name-directory load-file-name) "core/core-load-paths.el")) (require (quote core-spacemacs)) (spacemacs/init) (configuration-layer/sync) (spacemacs-buffer/display-startup-note) (spacemacs/setup-startup-hook) (require (quote server)) (if (server-running-p) nil (server-start)))
eval-buffer(#<buffer *load*> nil "/home/sujit/.emacs.d/init.el" nil t) ; Reading at buffer position 1264
load-with-code-conversion("/home/sujit/.emacs.d/init.el" "/home/sujit/.emacs.d/init.el" t t)
load("/home/sujit/.emacs.d/init" t t)
#[0 "\205\266\00 \306=\203\00\307\310Q\202?\00 \311=\204\00\307\312Q\202?\00\313\307\314\315#\203*\00\316\202?\00\313\307\314\317#\203>\00\320\321\322!D\nB\323\202?\00\316\324\325\324\211#\210\324=\203e\00\326\327\330\307\331Q!\"\325\324\211#\210\324=\203d\00\210\203\247\00\332!\333\232\203\247\00\334!\211\335P\336!\203\201\00\211\202\214\00\336!\203\213\00\202\214\00\314\262\203\245\00\337\"\203\243\00\340\341#\210\342\343!\210\266\f?\205\264\00\314\325\344\324\211#)\262\207" [init-file-user system-type delayed-warnings-list user-init-file inhibit-default-init inhibit-startup-screen ms-dos "~" "/_emacs" windows-nt "/.emacs" directory-files nil "^\\.emacs\\(\\.elc?\\)?$" "~/.emacs" "^_emacs\\(\\.elc?\\)?$" initialization format-message "`_emacs' init file is deprecated, please use `.emacs'" "~/_emacs" t load expand-file-name "init" file-name-as-directory "/.emacs.d" file-name-extension "elc" file-name-sans-extension ".el" file-exists-p file-newer-than-file-p message "Warning: %s is newer than %s" sit-for 1 "default"] 7]()
command-line()
normal-top-level()
Try setting the SHELL environment variable:
SHELL=/bin/bash emacs
I had the same problem and I have found the solution thanks to Seanjamesking
Add
(require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/")) (package-initialize)
to the top of the ~/.emacs.d/init.el file.
*I am using Emacs 25.2.2 on Ubuntu 18.04.3

How can I use doc view in emacs -nw?

Suppose I want to open the pdf file in the emacs. It is very easy in the emacs gui by using C-x C-f. But when I use it in emacs -nw. It shows the code instead of document. How can I do that? Thank you.
If you just want to read the pdf as text you can dot it with pdf2txt and this function:
(defun open-pdf-in-txt (arg)
(interactive "fpdf: ")
(shell-command
(format (concat "pdftotext " (replace-regexp-in-string " " "?\ " arg) " -layout")))
(find-file (replace-regexp-in-string "pdf" "txt" arg)))

How to stop auto-complete from overwriting a file that is similarly named

I am a new user to Emacs and have gotten a .emacs file from someone in my field that introduced me to this programming platform. However, I have been having some issues while trying to save or create new files that are named similar to those that already exist. If I attempt to create a new file that has a name that is relatively similar to one that exists, even if it is in a different directory, the existing file will be opened. When attempting to save a file with a shorter or similar name to an already existing file, Emacs attempts to overwrite the file instead of creating a new one.
For example, I am attempting to save the file growth_loglike.tpl but I already have the file growth_loglike_ADMB2_End.tpl in the directory. When I go to save and write in growth_loglike.tpl it shows [growth_loglike_ADMB2_End.tpl] in green to the right. When I hit enter it asks me if I want to overwrite growth_loglike_ADMB2_End.tpl. I think this is an issue with the auto-complete plugin. Is there a way to temporarily turn off the auto-complete? Looking at the auto-complete.el file my guess is that I need to change this variable but I'm not sure to what (or if that is even correct). Any help with this would be extremely helpful.
(defcustom ac-use-overriding-local-map nil
"Non-nil means `overriding-local-map' will be used to hack for overriding key events on auto-copletion."
:type 'boolean
:group 'auto-complete)
Below is the .emacs file that I am using.
;; This emacs configuration file will activate common packages
and
;; functionality used in the QFC Reproducable Reseach Workshop.
;; change this path to point to emacs directory in workshop on your computer:
;; (don't forget to include a trailing slash!)
(defvar workshop-root "C:/Users/vince151/Documents/workshop/")
(defvar emacs-root (concat (file-name-as-directory workshop-root) "emacs/"))
;;=============================================================================
;;=============================================================================
;; 1. Misc Plug-ins
;; here are some paths to look for additional scripts and functions:
(add-to-list 'load-path (concat emacs-root "plugins/"))
;;=============================================================================
;; 2. YASnippet
(add-to-list 'load-path (concat emacs-root "plugins/yasnippet"))
(require 'yasnippet) ;; not yasnippet-bundle
(setq yas-snippet-dirs (concat emacs-root "plugins/yasnippet/snippets"))
(yas-global-mode 1)
;; timestamp used in some yasnippets
(defun now ()
"Insert string for the current time formatted like '2:34 PM'."
(interactive) ; permit invocation in minibuffer
(insert (format-time-string "%D %-I:%M %p")))
;;=============================================================================
;; 3. Swap Slashes
;; swap slashes and backslashes in current line -- useful for converting paths to be Windows-readable
;;http://www.xsteve.at/prg/emacs/.emacs.txt
(defun xsteve-exchange-slash-and-backslash ()
"Exchanges / with \ and in the current line or in the region when a region-mark is active."
(interactive)
(save-match-data
(save-excursion
(let ((replace-count 0)
(eol-pos (if mark-active (region-end) (progn (end-of-line) (point))))
(bol-pos (if mark-active (region-beginning) (progn (beginning-of-line) (point)))))
(goto-char bol-pos)
(while (re-search-forward "/\\|\\\\" eol-pos t)
(setq replace-count (+ replace-count 1))
(cond ((string-equal (match-string 0) "/") (replace-match "\\\\" nil nil))
((string-equal (match-string 0) "\\") (replace-match "/" nil nil)))
(message (format "%d changes made." replace-count)))))))
(global-set-key (kbd "M-\\") 'xsteve-exchange-slash-and-backslash)
;;==============================================================================
;; 4. Parenthesis highlighting
(require 'highlight-parentheses)
(setq hl-paren-colors '("DodgerBlue1" "IndianRed" "cyan" "ForestGreen" "magenta" "SlateGrey"))
(defun hpm-on ()
(highlight-parentheses-mode t))
(add-hook 'admb-mode-hook 'hpm-on)
(add-hook 'ess-mode-hook 'hpm-on)
(add-hook 'inferior-ess-mode-hook 'hpm-on)
(add-hook 'latex-mode-hook 'hpm-on)
(add-hook 'LaTeX-mode-hook 'hpm-on)
;;=============================================================================
;; 5. ESS
;; path to current version of R: (This shouldn't be needed if PATH is correct)
;;(setq-default
;; inferior-R-program-name
;; "C:/R/R-2.15.0/bin/i386/Rterm.exe")
(load (concat emacs-root "ESS/ess-13.09/lisp/ess-site"))
(setq ess-fancy-comments nil)
;; make pdflatex the default sweave compiler (removes texi2pdf)
(setq ess-swv-pdflatex-commands '("pdflatex" "xelatex" "make"))
;;=============================================================================
;; 6. ADMB-ide
;; don't forget to edit setADMBpaths.bat to point to your admb installation
(setq admb-init (concat emacs-root "setADMBpaths & "))
;; these commands were cut from admb.el
(load (concat emacs-root "plugins/admb"))
;; Edit .emacs so that `admb-mode' is autoloaded and assigned to *.tpl files:
(autoload 'admb-mode "admb" "Edit ADMB code." t)
(add-to-list 'auto-mode-alist '("\\.tpl$" . admb-mode))
;; If you're running Emacs in MS Windows, add a line so *.tpl files are not treated as binary:
(setq file-name-buffer-file-type-alist nil)
;; You may want to assign a mode that recognizes #comments in *.dat files (perl-mode, conf-space-mode, or R-mode):
(add-to-list 'auto-mode-alist '("\\.dat$" . perl-mode))
;;(add-to-list 'auto-mode-alist '("\\.dat$" . admb-mode))
;;(add-to-list 'auto-mode-alist '("\\.dat$" . easy-admb-hook))
;;added Monday, March 29, 2010 so that we can run models from within dat files
(add-hook 'perl-mode-hook
(lambda()
(define-key perl-mode-map [f9] 'admb-run)))
;;these commands were taken from Arni Magnusen's emacs file distributed with ADMB-IDE
(defun easy-admb-hook ()
(local-set-key [f1] 'admb-help ) ; prefix
(local-set-key [f2] 'admb-mode ) ; prefix
;;(global-set-key [f3] 'conf-space-mode ) ; kmacro-start-macro-or-insert-counter
(local-set-key [f4] 'admb-toggle-window ) ; kmacro-end-or-call-macro
(local-set-key [f7] 'admb-tpl2cpp )
(local-set-key [f8] 'admb-build )
(local-set-key [f9] 'admb-run )
(local-set-key [S-f9] 'admb-run-args )
(local-set-key [f10] 'admb-rep ) ; menu-bar-open
(local-set-key [S-f10] 'admb-cor )
(local-set-key [?\C-.] 'admb-toggle-section))
(add-hook 'admb-mode-hook 'easy-admb-hook)
;;----------
;; C++
;;----------
(defun easy-gdb-hook ()
(message nil)
(setq indent-line-function 'gud-gdb-complete-command)
;;(setq gdb-show-main t)
(local-set-key [f5] 'gdb-restore-windows)
(local-set-key [M-up] 'gdb-io-buffer-off )
(local-set-key [M-down] 'gdb-io-buffer-on )
(local-set-key [?\C-c ?\C-q] 'comint-quit-subjob )
(defun gdb-io-buffer-off () "Enable separate IO buffer." (interactive)(gdb-use-separate-io-buffer nil))
(defun gdb-io-buffer-on () "Disable separate IO buffer." (interactive)(gdb-use-separate-io-buffer t)))
(add-hook 'gdb-mode-hook 'easy-gdb-hook)
;;=================
;; enable YASnippet
(add-hook 'admb-mode-hook 'yas/minor-mode-on)
(add-hook 'admb-mode-hook
(let ((original-command (lookup-key admb-mode-map [tab])))
`(lambda ()
(setq yas/fallback-behavior '(apply ,original-command))
(local-set-key [tab] 'yas/expand))))
;;==============================================================================
;; 7. Git
;; path to git executable: (This shouldn't be needed if PATH is correct)
;; (setq-default
;; magit-git-executable
;; "C:/gnu/git/bin/git.exe")
;;(require 'git)
(add-to-list 'load-path (concat emacs-root "plugins/git/magit"))
(load (concat emacs-root "plugins/git/magit/magit.el"))
(require 'magit)
;; use Ctrl-C G to start Git:
(global-set-key "\C-c\C-g" 'magit-status)
;; from: http://readystate4.com/2011/02/22/emacs-changing-magits-default-diff-colors/
;; change magit diff colors
(eval-after-load 'magit
'(progn
(set-face-foreground 'magit-diff-add "green3")
(set-face-foreground 'magit-diff-del "red3")
(when (not window-system)
(set-face-background 'magit-item-highlight "black"))))
;;==============================================================================
;; 8. autocomplete
(require 'auto-complete)
(add-to-list 'ac-dictionary-directories (concat emacs-root "plugins/ac-dict"))
(require 'auto-complete-config)
(ac-config-default)
;;========================================
;; 9. Bibtex database:
(setq reftex-default-bibliography
'("C:/Users/vince151/Documents/workshop/utils/references.bib"))
(setq reftex-default-bibliography
(concat workshop-root "utils/references.bib"))
(defvar reftex-file
(concat
(file-name-as-directory workshop-root) "utils/references.bib"))
(setq reftex-default-bibliography reftex-file)
;; Make TeX and RefTex aware of Snw and Rnw files
(setq reftex-file-extensions
'(("snw" "rnw" "Snw" "Rnw" "nw" "tex" ".tex" ".ltx") ("bib" ".bib")))
(setq TeX-file-extensions
'("snw" "rnw" "Snw" "Rnw" "nw" "tex" "sty" "cls" "ltx" "texi" "texinfo"))
(add-hook 'latex-mode-hook 'turn-on-reftex)
;;========================================
;; 10. Some functions to run bibtex and latex
(defun ac-run-bibtex ()
"Run BibTex on the current file."
(interactive)
(save-excursion
(let* ((latex-filename (file-name-sans-extension (buffer-file-name)))
(tex-buf (get-buffer-create " *ESS-bibtex-output*")))
(message "Running BibTex on '%s' ..." latex-filename)
(switch-to-buffer tex-buf)
(call-process "bibtex" nil tex-buf 1 latex-filename)
(switch-to-buffer (buffer-name))
(display-buffer tex-buf)
(message "Finished running BibTeX" ))))
(defun ac-run-pdflatex ()
"Run pdflatex on the current file."
(interactive)
(save-excursion
(let* ((namestem (file-name-sans-extension (buffer-file-name)))
(latex-filename (concat namestem ".tex"))
(tex-buf (get-buffer-create " *pdflatex-output*")))
(message "Running pdflatex on '%s' ..." latex-filename)
(switch-to-buffer tex-buf)
(call-process "pdflatex" nil tex-buf 1 latex-filename)
(switch-to-buffer (buffer-name))
(display-buffer tex-buf)
(message "Finished running pdflatex" ))))
;; terms associated with base name were added to create index files using makeindex
;; this function impliments the following sequence of calls:
;; pdflatex -> bibtex -> pdflatex -> makeindex -> pdflatex
(defun ac-run-lbll ()
"Run LaTeX-BibTex-Latex-Latex on the current file."
(interactive)
(save-excursion
(let* ((namestem (file-name-sans-extension (buffer-file-name)))
(latex-filename (concat namestem ".tex"))
(basename (file-name-nondirectory namestem))
(tex-buf (get-buffer-create " *lbll-output*")))
(message "Running LaTeX-BibTex-Latex-Latex on '%s' ..." latex-filename)
(switch-to-buffer tex-buf)
(call-process "pdflatex" nil tex-buf 1 latex-filename)
(call-process "bibtex" nil tex-buf 1 namestem)
(call-process "pdflatex" nil tex-buf 1 latex-filename)
(call-process "makeindex" nil tex-buf 1 basename)
(call-process "pdflatex" nil tex-buf 1 latex-filename)
(switch-to-buffer (buffer-name))
(display-buffer tex-buf)
(message "Finished running LaTeX-BibTex-Latex-Latex" ))))
(add-hook 'latex-mode-hook
(lambda ()
(define-key latex-mode-map [f9] 'ac-run-pdflatex)
)
)
;;========================================
;; 10. Other useful functions below this point
;;ispell - super cool spell checker for emacs
(setq-default ispell-program-name (concat emacs-root "aspell/bin/aspell.exe"))
;; get itspell to skip sweave chunks:
(add-to-list 'ispell-skip-region-alist '("^<<.*>>=" . "^#"))
;;=============================================================================
;; use string rectangle for indentng blocks/regions of code
(global-set-key (kbd "C->") 'string-insert-rectangle)
;;=============================================================================
;;ido (from: http://www.emacswiki.org/emacs/InteractivelyDoThings)
(require 'ido)
(ido-mode t)
(setq ido-enable-flex-matching t) ;; enable fuzzy matching
;;=============================================================================
;; use ibuffer anytime we would have use buffer-list
(defalias 'list-buffers 'ibuffer)
; get rid of prompt that forces you to type full "yes" or "no".
; y or n is enough
(defalias 'yes-or-no-p 'y-or-n-p)
;;==============================================================================
;; from http://www.joegrossberg.com/archives/000182.html
;; enable recent file list - bound to C-x C-r
(require 'recentf)
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)
;;==============================================================================
;; from http://www.stokebloke.com/wordpress/2008/04/17/emacs-refresh-f5-key/
;; use f3 to refresh file in current buffer
;;(defun refresh-file ()
;; (interactive)
;; (revert-buffer t t t)
;; )
;;(global-set-key [f3] 'refresh-file)
;;
;;==============================================================================
;; copy path of current buffer to kill ring
;; from:http://stackoverflow.com/questions/3669511/
(defun copy-full-path-to-kill-ring ()
"copy buffer's full path to kill ring"
(interactive)
(when buffer-file-name
(kill-new (file-truename buffer-file-name))))
(global-set-key "\C-cz" 'copy-full-path-to-kill-ring)
;;==============================================================================
;; keep emacs from cluttering working directories with tilde files by
;; placing them here:(concat emacs-root "tildes") instead of
;; wherever we're working.
(defvar user-temporary-file-directory
(concat emacs-root "tildes/"))
(make-directory user-temporary-file-directory t)
(setq backup-by-copying t)
(setq backup-directory-alist
`(("." . ,user-temporary-file-directory)
(,tramp-file-name-regexp nil)))
(setq auto-save-list-file-prefix
(concat user-temporary-file-directory ".auto-saves-"))
(setq auto-save-file-name-transforms
`((".*" ,user-temporary-file-directory t)))
;;;============================================================================
; try to improve slow performance on windows.
;;Got this from a website that said this would help.
(setq w32-get-true-file-attributes nil)
This is the default behaviour of ido-mode. There are two things you can do about it:
Once you've typed the filename you want, hit C-j instead of RET. This makes ido-mode use the filename exactly as you typed it.
You can temporarily switch back to the "normal" minibuffer behaviour by hitting C-f. Then you can tab-complete the old filename, and edit it as needed.