(defun auto-complete-mode-maybe ()
  "Overwrite auto-complete-mode-maybe which by defaults turns autocomplete only for buffers listed in ac-modes."
  (unless (minibufferp (current-buffer))
	(auto-complete-mode 1)
  )
  )

(defun set-exec-path-from-shell-PATH ()
  (let ((path-from-shell (replace-regexp-in-string
                          "[ \t\n]*$"
                          ""
                          (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
    (setenv "PATH" path-from-shell)
    (setq eshell-path-env path-from-shell) ; for eshell users
    (setq exec-path (split-string path-from-shell path-separator)))
  )

(defun cnt-occur ()
  (interactive)
  (count-matches (region-beginning) (region-end))
  )

(defun revert-cp1251()
  (interactive)
  (defvar old-revert-without-query revert-without-query)
  (setq revert-without-query '(".*"))
  (revert-buffer-with-coding-system 'cp1251)
  (setq revert-without-query 'old-revert-without-query)
  )

(defun revert-buf()
  (interactive)
  (defvar old-revert-without-query revert-without-query)
  (setq revert-without-query '(".*"))
  (revert-buffer)
  (setq revert-without-query 'old-revert-without-query)  
  )

(defun move-text-internal (arg)
  (cond
   ((and mark-active transient-mark-mode)
    (if (> (point) (mark))
        (exchange-point-and-mark))
    (let ((column (current-column))
          (text (delete-and-extract-region (point) (mark))))
      (forward-line arg)
      (move-to-column column t)
      (set-mark (point))
      (insert text)
      (exchange-point-and-mark)
      (setq deactivate-mark nil)))
   (t
    (let ((column (current-column)))
      (beginning-of-line)
      (when (or (> arg 0) (not (bobp)))
        (forward-line)
        (when (or (< arg 0) (not (eobp)))
          (transpose-lines arg)
          (when (and (eval-when-compile
                       '(and (>= emacs-major-version 24)
                             (>= emacs-minor-version 3)))
                     (< arg 0))
            (forward-line -1)))
        (forward-line -1))
      (move-to-column column t))))
  )

(defun move-text-down (arg)
  "Move region (transient-mark-mode active) or current line
  arg lines down."
  (interactive "*p")
  (move-text-internal arg)
  )

(defun move-text-up (arg)
  "Move region (transient-mark-mode active) or current line
  arg lines up."
  (interactive "*p")
  (move-text-internal (- arg))
  ;;(next-line)
  )

(defun m-line-up()
  (interactive)
  (transpose-lines 1)
  (forward-line -2)
  )

(defun m-line-down()
  (interactive)
  (forward-line 1)
  (transpose-lines 1)
  (forward-line -1)
  )

(defun execute-cpp-program()
  (interactive)
  (save-buffer)
  (defvar foo)
  (setq foo (concat "g++ -O3 -std=c++14 -pthread " (buffer-name) " && ./a.out" ))
  (shell-command foo)
  )

(defun execute-python-script()
  (interactive)
  (save-buffer)
  (defvar foo)
  (setq foo (concat "python " (buffer-name)))
  (shell-command foo)
  )

(setq rm-spcs-kmap
      (let ((map (make-sparse-keymap)))
        (define-key map (kbd "s") #'remove-spaces)
        map))

(defun remove-spaces()
  (interactive)
  (delete-char 1)
  (forward-char)
  (set-transient-map
   rm-spcs-kmap)
  )
