Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
160 lines (134 sloc) 4.56 KB
;;; kemacs-defuns.el --- Custom functions
;; Part of kEmacs
(defun insert-path (file)
"insert file"
(interactive "FPath: ")
(insert (expand-file-name file)))
;; full screen toggle using command+[RET]
(defun toggle-fullscreen ()
(set-frame-parameter nil 'fullscreen (if (frame-parameter nil 'fullscreen)
(defun indendt-whole-buffer ()
"indent whole buffer"
;; (delete-trailing-whitespace)
(indent-region (point-min) (point-max))
;; (untabify (point-min) (point-max))
(defun search-site-url (keyword &optional site inurl lucky)
"Do a Google search for KEYWORD. Restrict to SITE and INURL, if specified.
Jump to best match (I Feel Lucky) if LUCKY set.
(concat ""
(format "search?q=%s" (url-hexify-string keyword))
(if site (format "+site:%s" (url-hexify-string site)))
(if inurl (format "+inurl:%s" (url-hexify-string inurl)))
(if lucky "&btnI")))
(defun ask-google (start end)
"Open browser, request google with string.
if there is active region - use it
if not - use current 'thing'(command/word/etc).
(interactive "r")
(search-site-url (if (eq mark-active nil)
(thing-at-point 'symbol)
(buffer-substring start end)
(defun get-file-basename (file-name)
"Substitute basename from file-name.
(substring file-name 0 (- (length file-name)
(length (file-name-extension file-name))
(defun get-buffer-name (&optional strip-extension)
"Return current buffer name.
If buffer is associated with the file - get filename only, without path.
If not - just buffer name.
If strip-extension is not nil - remove file extension.
(let ((name (if (buffer-file-name)
(file-name-nondirectory (buffer-file-name))
(if (not (eq strip-extension nil))
(get-file-basename name)
(defun insert-date (prefix)
"Insert the current date. With prefix-argument, use ISO format. With
two prefix arguments, write out the day and month name."
(interactive "P")
(let ((format (cond
((not prefix) "%d/%m/%Y")
((equal prefix '(4)) "%Y-%m-%d")
((equal prefix '(16)) "%d %B %Y, %A")))
;; (system-time-locale "ru_RU")
(insert (format-time-string format))))
(defun coding-hook ()
"Enable things that are convenient across all coding buffers."
(set (make-local-variable 'comment-auto-fill-only-comments) t)
(make-local-variable 'column-number-mode)
(column-number-mode t)
(setq save-place t)
(auto-fill-mode) ;; in comments only
(if window-system (hl-line-mode t))
(defun dh ()
"Connect to the"
(find-file "/")
(defun aldan ()
"Connect to the aldan_intoVps server"
(find-file "/ssh:konsty@")
;;; Window management
(defun window-split-horizontally-if-alone ()
"Split the window horizontally for temp buffers."
(when (and (one-window-p t)
(not (active-minibuffer-window)))
;; Now emacs will split window horizontally for temporary buffers.
(add-hook 'temp-buffer-setup-hook 'window-split-horizontally-if-alone)
(defun switch-to-buffer-other-window-horizontal ()
"Replacement for switch-to-buffer-other-window.
It does the same, but splits window horizontally."
(defun find-file-other-window-horizontal ()
"Replacement for find-file-other-window.
It does the same, but splits window horizontally."
(defun fake-stdin-slurp (filename)
"Emulate stdin slurp using emacsclient hack"
(switch-to-buffer (generate-new-buffer "*stdin*"))
(insert-file filename)
(defun set-input-method-russian ()
(set-input-method 'russian-computer)
(defun buffer-exists (bufname)
"Check if buffer exists"
(not (eq nil (get-buffer bufname)))
(provide 'kemacs-defuns)
;;; kemacs-defuns.el ends here