;; Ilya Solnyshkin's edition ;; File .emacs - These commands are executed when GNU emacs starts up. ;; ;;; My location for external packages. (add-to-list 'load-path "/usr/share/emacs/site-lisp") ;;; My location for external packages. (add-to-list 'load-path "~/.emacs.d/site-lisp") ;; See if we're on MS Windows or Mac OS X (defvar mswindows-p (string-match "windows" (symbol-name system-type))) (defvar macosx-p (string-match "darwin" (symbol-name system-type))) ;; Keep Emacs from executing file local variables. ;; (this is also in the site-init.el file loaded at emacs dump time.) (setq inhibit-local-variables t ; v18 enable-local-variables nil ; v19 enable-local-eval nil) ; v19 ;; Swap Backspace and Delete keys, except for v19 running under X. This works ;; on both HPs and Suns. (or (and (eq window-system 'x) (string-match "\\`19\\." emacs-version)) (load "term/bobcat")) ;; Cause the region to be highlighted and prevent region-based commands ;; from running when the mark isn't active. (pending-delete-mode t) (setq transient-mark-mode t) (setq kill-emacs-query-functions (list (function (lambda () (ding) (y-or-n-p "Really quit? "))))) ;; Fonts are automatically highlighted. For more information ;; type M-x describe-mode font-lock-mode (global-font-lock-mode t) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; ;;;; This provides customized support for writing programs in different kinds ;;;; of programming languages. ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Load the C++ and C editing modes and specify which file extensions ;; correspond to which modes. (autoload 'python-mode "python-mode" "Python editing mode." t) (setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist)) (setq interpreter-mode-alist (cons '("python" . python-mode) interpreter-mode-alist)) (autoload 'c++-mode "cc-mode" "C++ Editing Mode" t) (autoload 'c-mode "c-mode" "C Editing Mode" t) (setq auto-mode-alist (append '(("\\.C\\'" . c++-mode) ("\\.cc\\'" . c++-mode) ("\\.c\\'" . c-mode) ("\\.h\\'" . c++-mode)) auto-mode-alist)) ;; set tab distance to something, so it doesn't change randomly and confuse people (setq c-basic-offset 4) ;; This function is used in various programming language mode hooks below. It ;; does indentation after every newline when writing a program. (defun newline-indents () "Bind Return to `newline-and-indent' in the local keymap." (local-set-key "\C-m" 'newline-and-indent)) ;; Tell Emacs to use the function above in certain editing modes. (add-hook 'lisp-mode-hook (function newline-indents)) (add-hook 'emacs-lisp-mode-hook (function newline-indents)) (add-hook 'lisp-interaction-mode-hook (function newline-indents)) (add-hook 'scheme-mode-hook (function newline-indents)) (add-hook 'c-mode-hook (function newline-indents)) (add-hook 'c++-mode-hook (function newline-indents)) ;; Fortran mode provides a special newline-and-indent function. (add-hook 'fortran-mode-hook (function (lambda () (local-set-key "\C-m" 'fortran-indent-new-line)))) ;; Text-based modes (including mail, TeX, and LaTeX modes) are auto-filled. (add-hook 'text-mode-hook (function turn-on-auto-fill)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; ;;;; This makes "M-x compile" smarter by trying to guess what the compilation ;;;; command should be for the C, C++, and Fortran language modes. ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; By requiring `compile' at this point, we help to ensure that the global ;; value of compile-command is set properly. If `compile' is autoloaded when ;; the current buffer has a buffer-local copy of compile-command, then the ;; global value doesn't get set properly. (require 'compile) ;; This gives the form of the default compilation command for C++, C, and ;; Fortran programs. Specifying the "-lm" option for C and C++ eliminates a ;; lot of potential confusion. (defvar compile-guess-command-table '((c-mode . "gcc -Wall -g %s -o %s -lm"); Doesn't work for ".h" files. (c++-mode . "g++ -g %s -o %s -lm") ; Doesn't work for ".h" files. (fortran-mode . "f77 -C %s -o %s") ) "*Association list of major modes to compilation command descriptions, used by the function `compile-guess-command'. For each major mode, the compilation command may be described by either: + A string, which is used as a format string. The format string must accept two arguments: the simple (non-directory) name of the file to be compiled, and the name of the program to be produced. + A function. In this case, the function is called with the two arguments described above and must return the compilation command.") ;; This code guesses the right compilation command when Emacs is asked ;; to compile the contents of a buffer. It bases this guess upon the ;; filename extension of the file in the buffer. (defun compile-guess-command () (let ((command-for-mode (cdr (assq major-mode compile-guess-command-table)))) (if (and command-for-mode (stringp buffer-file-name)) (let* ((file-name (file-name-nondirectory buffer-file-name)) (file-name-sans-suffix (if (and (string-match "\\.[^.]*\\'" file-name) (> (match-beginning 0) 0)) (substring file-name 0 (match-beginning 0)) nil))) (if file-name-sans-suffix (progn (make-local-variable 'compile-command) (setq compile-command (if (stringp command-for-mode) ;; Optimize the common case. (format command-for-mode file-name file-name-sans-suffix) (funcall command-for-mode file-name file-name-sans-suffix))) compile-command) nil)) nil))) ;; Add the appropriate mode hooks. (add-hook 'c-mode-hook (function compile-guess-command)) (add-hook 'c++-mode-hook (function compile-guess-command)) (add-hook 'fortran-mode-hook (function compile-guess-command)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; ;;;; This creates and adds a "Compile" menu to the compiled language modes. ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar compile-menu nil "The \"Compile\" menu keymap.") (defvar check-option-modes nil "The list of major modes in which the \"Check\" option in the \"Compile\" menu should be used.") (defvar compile-menu-modes nil "The list of major modes in which the \"Compile\" menu has been installed. This list used by the function `add-compile-menu-to-mode', which is called by various major mode hooks.") ;; Create the "Compile" menu. (if compile-menu nil (setq compile-menu (make-sparse-keymap "Compile")) ;; Define the menu from the bottom up. (define-key compile-menu [first-error] '(" First Compilation Error" . first-compilation-error)) (define-key compile-menu [prev-error] '(" Previous Compilation Error" . previous-compilation-error)) (define-key compile-menu [next-error] '(" Next Compilation Error" . next-error)) (define-key compile-menu [goto-line] '(" Line Number..." . goto-line)) (define-key compile-menu [goto] '("Goto:" . nil)) ;; (define-key compile-menu [indent-region] '("Indent Selection" . indent-region)) (define-key compile-menu [make] '("Make..." . make)) (define-key compile-menu [check-file] '("Check This File..." . check-file)) (define-key compile-menu [compile] '("Compile This File..." . compile)) ) ;;; Enable check-file only in Fortran mode buffers (put 'check-file 'menu-enable '(eq major-mode 'fortran-mode)) ;;; Here are the new commands that are invoked by the "Compile" menu. (defun previous-compilation-error () "Visit previous compilation error message and corresponding source code. See the documentation for the command `next-error' for more information." (interactive) (next-error -1)) (defun first-compilation-error () "Visit the first compilation error message and corresponding source code. See the documentation for the command `next-error' for more information." (interactive) (next-error '(4))) (defvar check-history nil) (defun check-file () "Run ftnchek on the file contained in the current buffer" (interactive) (let* ((file-name (file-name-nondirectory buffer-file-name)) (check-command (read-from-minibuffer "Check command: " (format "ftnchek %s" file-name) nil nil '(check-history . 1)))) (save-some-buffers nil nil) (compile-internal check-command "Can't find next/previous error" "Checking" nil nil nil))) (defun make () "Run make in the directory of the file contained in the current buffer" (interactive) (save-some-buffers nil nil) (compile-internal (read-from-minibuffer "Make command: " "make ") "Can't find next/previous error" "Make" nil nil nil)) ;;; Define a function to be called by the compiled language mode hooks. (defun add-compile-menu-to-mode () "If the current major mode doesn't already have access to the \"Compile\" menu, add it to the menu bar." (if (memq major-mode compile-menu-modes) nil (local-set-key [menu-bar compile] (cons "Compile" compile-menu)) (setq compile-menu-modes (cons major-mode compile-menu-modes)) )) ;; And finally, make sure that the "Compile" menu is available in C, C++, and ;; Fortran modes. (add-hook 'c-mode-hook (function add-compile-menu-to-mode)) (add-hook 'c++-c-mode-hook (function add-compile-menu-to-mode)) (add-hook 'c++-mode-hook (function add-compile-menu-to-mode)) (add-hook 'fortran-mode-hook (function add-compile-menu-to-mode)) ;; This is how emacs tells the file type by the file suffix. (setq auto-mode-alist (append '(("\\.mss$" . scribe-mode)) '(("\\.bib$" . bibtex-mode)) '(("\\.tex$" . latex-mode)) '(("\\.obj$" . lisp-mode)) '(("\\.st$" . smalltalk-mode)) '(("\\.Z$" . uncompress-while-visiting)) '(("\\.cs$" . indented-text-mode)) '(("\\.C$" . c++-mode)) '(("\\.cc$" . c++-mode)) '(("\\.icc$" . c++-mode)) '(("\\.c$" . c-mode)) '(("\\.y$" . c-mode)) '(("\\.h$" . c++-mode)) auto-mode-alist)) ;; ;;;========================iLYA (require 'prh-bufsw) (setq stesla-hated-buffer-regexps '("^ " "*Buffer" "^\\*trace" "^\\*tramp" "^\\*Messages")) (pc-bufsw::bind-keys [C-tab] [C-S-tab]) (setq pc-bufsw::quite-time 1) ;; kill current buffer (defun prh:kill-current-buffer () (interactive) (kill-buffer (current-buffer))) (global-set-key (kbd "C-x w") 'prh:kill-current-buffer) ;; customize a few things (custom-set-variables '(tab-width 4)) (global-set-key (kbd "M-SPC") 'hippie-expand) ;;ou'll have access to moving around between the different windows in your frame, using Shift+Arrowkeys. (windmove-default-keybindings) ;;will inhibit startup messages. (setq inhibit-startup-message t) ;;will allow you to type just "y" instead of "yes" when you exit. (fset 'yes-or-no-p 'y-or-n-p) (load-library "cua") (require 'cua) (CUA-mode t) (if macosx-p (progn (require 'cua-base) (cua-mode t) ;; fix a mac-specific problem with ptys (setq process-connection-type nil) ;; repair bogus default directory (if (equal default-directory "/") (setq default-directory "~/")) ;; Mac-style cut/copy/paste (setq mac-command-key-is-meta nil) (setq cua-enable-cua-keys nil) (global-set-key [(alt x)] 'cua-cut-region) (global-set-key [(alt c)] 'cua-copy) (global-set-key [(alt v)] 'cua-paste) (global-set-key [(alt a)] 'mark-whole-buffer) (global-set-key [(alt s)] 'save-buffer) (global-set-key [(alt S)] 'write-file) (global-set-key [(alt p)] 'ps-print-buffer) (global-set-key [(alt o)] 'find-file) (global-set-key [(alt q)] 'save-buffers-kill-emacs) (global-set-key [(alt w)] 'kill-buffer-and-window) (global-set-key [(alt z)] 'undo) (global-set-key [(alt f)] 'isearch-forward) (global-set-key [(alt g)] 'query-replace) (global-set-key [(alt l)] 'goto-line) (global-set-key [(alt m)] 'iconify-frame) (global-set-key [(alt n)] 'new-frame) (global-set-key [kp-delete] 'delete-char) (global-set-key [(control kp-home)] 'beginning-of-buffer) (global-set-key [(control kp-end)] 'end-of-buffer) (mac-key-mode 1) )) ;; disable backup (setq backup-inhibited t) (require 'browse-kill-ring) (load-library "browse-kill-ring") (global-set-key (kbd "C-S-v") 'browse-kill-ring) (require 'font-lock) (if (fboundp 'global-font-lock-mode) (global-font-lock-mode 1)) (load "color-theme") (color-theme-classic) ;; pick a favorite theme (load-library "highlight-completion") (setq query-replace-highlight t) ; Highlight query object (global-set-key [(f7)] 'compile) (setq compilation-window-height 8) (setq compilation-finish-function (lambda (buf str) (if (string-match "exited abnormally" str) ;;there were errors (message "compilation errors, press C-x ` to visit") ;;no errors, make the compilation window go away in 0.5 seconds (run-at-time 0.5 nil 'delete-windows-on buf) (message "NO COMPILATION ERRORS!")))) (put 'downcase-region 'disabled nil) (put 'upcase-region 'disabled nil) ;; Scroll down with the cursor,move down the buffer one ;; line at a time, instead of in larger amounts. (setq scroll-step 1) (setq column-number-mode 1) ;; Finally look for .customs.emacs file and load it if found (if "~/.customs.emacs" (load "~/.customs.emacs" t t)) ;; End of file.