diff --git a/.hgignore b/.hgignore deleted file mode 100755 index 1def653..0000000 --- a/.hgignore +++ /dev/null @@ -1,18 +0,0 @@ -.pydevproject -.pida-metadata -.pida-metadata/python/* -.pida-metadata/* -.DS_Store -syntax: glob -*.pyc -*~ -\#* -\.\#* -.settings/* -*Thumbs.db -*.swp -*.kpf -*.log -*.e4p -*.wpr -data/* diff --git a/README.md b/README.md index fe94057..a46135a 100755 --- a/README.md +++ b/README.md @@ -4,13 +4,12 @@ A piece of Shit GNU Emacs based IDE Copyright (C) 2010-2013 Sameer Rahmani Contents --------- - +======== 1. License 2. Dependencies 1. License ----------- +========== Kuso IDE is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -29,32 +28,37 @@ with this program; if not, write to the Free Software Foundation, Inc., under the term of GNU FDL. 2. Dependencies ---------------- +=============== Kuso IDE required these softwares: * GNU Emacs -Python dependencies -------------------- +Python dependencies (kuso-python plugin) +---------------------------------------- * pep8 * pyflakes * pychecker * pylint - -For autocompetion: * jedi * epc +Ruby dependencies (kuso-ruby plugin) +------------------------------------ + * rb-readline + * Rake + * Bundle + HTML dependencies ----------------- * tidy + * xmlstarlet CSS dependencies ---------------- * python-cssutils (pip install cssutils) - + * csslint 3. Installation ---------------- -Just run install.sh in its directory +=============== +Just run install.sh in its directory and after that run kuso to get extra plugins diff --git a/TODO.org b/TODO.org index 15bc456..3831e6d 100644 --- a/TODO.org +++ b/TODO.org @@ -1,18 +1,19 @@ -* High Priority - define prefix key map for language plugins - define a prefix keymap for kuso-mode so some plugins can use that safely - byte compile the installed .d directory using emacs --batch --eval '(byte-recompile-directory ".")' -* Normal Priority - Remove unkown filetypes from filelist in load-dir - Add some option for user to choose between liceenses - Review license templates - Build the debian folder nad required files for deb packages - Escape project name for a unix name "shell-quote-argument" - Disable EDE and other unused menu - Allow templates file to store in subdirectories so new project can - have subdirectories - Improve modes.el file documentation - add the license name into kernel module c file - make sure cplugin keymap load with cplugin +* Tasks ** Workgroups - Add a directory scanning mode. load each workgroup by name only. +*** TODO Add a directory scanning mode. load each workgroup by name only. +** TODO Provide a variable (defcustom) which allow user to easily change them from customize menu +** DONE Add auto-pair mode to kuso-base +** TODO Add 'helm mode' +** TODO add markdown and rst plugin +** TODO add org-mode support +*** TODO add support to main todo repository and collect todo form projects repositories +** TODO add startup custom buffer for kuso +** TODO add per project configuration support +** Ruby Mode +*** TODO activate rinari mode by default +* New Plugings +** TODO Add hs-minor-mode to the plugin mojor mode load hook +** TODO add the custom snippets path to yasnippet load path + +* Release +** TODO remove '-dev' suffix from executable filename diff --git a/bin/kuso b/bin/kuso index 37f94d4..61a914a 100755 --- a/bin/kuso +++ b/bin/kuso @@ -1,3 +1,3 @@ #! /bin/sh -emacs --title KusoIDE -q -l ~/.kuso $1 \ No newline at end of file +emacs --no-splash --name KusoIDE --title KusoIDE -q -l ~/.kuso $1 diff --git a/conf/dotkuso b/conf/dotkuso index 77011cc..d11e4a2 100644 --- a/conf/dotkuso +++ b/conf/dotkuso @@ -1,303 +1,31 @@ -;; Setup load directory -(add-to-list 'load-path "~/.kuso.d/") +(add-to-list 'load-path "--REPO--") -;; General configuration --------------------------------------------------------- -(tool-bar-mode -1) -(scroll-bar-mode -1) -(setq x-select-enable-clipboard t) -(column-number-mode t) -(global-linum-mode) +(setq developer-name "--FULLNAME--") +(setq developer-email "--EMAIL--") +(setq kuso-workspace "--WORKSPACE--") -;; Setting up color them ------------------------------------------------------- -(eval-after-load "color-theme" - '(progn - (color-theme-initialize) - (color-theme-tomorrow-night-eighties) -)) +(setq el-get-dir "--REPO--/") +(setq el-get-git-install-url "http://github.com/KusoIDE/el-get.git") -;; Setting up customization ----------------------------------------------------- -(custom-set-variables - ;; custom-set-variables was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - '(c-plugin nil) - ;'(color-theme-selection "Arjen" nil (color-theme_seldefcustom)) - '(developer-email "--EMAIL--") - '(developer-name "--FULLNAME--") - '(kuso-workspace "--WORKSPACE--") - '(face-font-family-alternatives (quote (("courier" "Monospace" "fixed") ("courier" "CMU Typewriter Text" "fixed") ("Sans Serif" "helv" "helvetica" "arial" "fixed") ("helv" "helvetica" "arial" "fixed")))) - '(inhibit-startup-screen t) - '(rng-nxml-auto-validate-flag nil)) -(custom-set-faces - ;; custom-set-faces was added by Custom. - ;; If you edit it by hand, you could mess it up, so be careful. - ;; Your init file should contain only one such instance. - ;; If there is more than one, they won't work right. - '(font-lock-comment-face ((t (:foreground "orange red")))) - '(font-lock-keyword-face ((t (:foreground "DeepSkyBlue1"))))) +(add-to-list 'load-path "--REPO--/el-get/") -(set-frame-font "Terminus-9") +(unless (require 'el-get nil t) + (with-current-buffer + (url-retrieve-synchronously + "https://raw.github.com/KusoIDE/el-get/master/el-get-install.el") + (let (el-get-master-branch) + (goto-char (point-max)) + (eval-print-last-sexp)) + ) + ) -;; HideShow -------------------- -(load-library "hideshow") -(global-set-key (kbd "C-\-") 'hs-toggle-hiding) -(global-set-key (kbd "C-\\") 'toggle-selective-display) +;; Uncomment this line if you want to debug an error +;; (toggle-debug-on-error) -(add-hook 'emacs-lisp-mode-hook 'hs-minor-mode) -(add-hook 'java-mode-hook 'hs-minor-mode) -(add-hook 'lisp-mode-hook 'hs-minor-mode) -(add-hook 'perl-mode-hook 'hs-minor-mode) -(add-hook 'sh-mode-hook 'hs-minor-mode) -(add-hook 'python-mode-hook 'hs-minor-mode) -(add-hook 'js-mode-hook 'hs-minor-mode) +(setq kuso:el-get-packages + '(kuso-base + kuso-python + kuso-ruby) + ) -(require 'fringe-helper) -(autoload 'hideshowvis-enable "hideshowvis" "Highlight foldable regions") -(autoload 'hideshowvis-minor-mode - "hideshowvis" - "Will indicate regions foldable with hideshow in the fringe." - 'interactive) -(dolist (hook (list 'emacs-lisp-mode-hook - 'c++-mode-hook - 'python-mode-hook)) - (add-hook hook 'hideshowvis-enable)) - - -;; auto complete ------------------------------------------------------------ -(require 'auto-complete-config) -(add-to-list 'ac-dictionary-directories "~/.kuso.d/ac-dict") -(ac-config-default) - -(global-auto-complete-mode t) - -;;dabbrev;; -;; dabbrev configuration ---------------------------------------------------------- -(require 'ac-dabbrev) -(setq ac-sources - (list ac-source-dabbrev - )) -(global-set-key (kbd "") 'dabbrev-expand) -;;/dabbrev;; - -;; ssh configuration --------------------------------------------------------- -(setq tramp-default-method "ssh") - -;;python-mode;; -;; python configuration ------------------------------------------------------ -(autoload 'python-mode "python-mode" "Python Mode." t) -(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode)) -(add-to-list 'interpreter-mode-alist '("python" . python-mode)) -(require 'python-mode) -(define-key py-mode-map (kbd "\C-c @") 'uncomment-region) - -(autoload 'python-pylint "python-pylint") -(autoload 'pylint "python-pylint") - -;;/python-mode;; - -;;python-autocomplete;; -;; python autocomplete ------------------------------------------------------- -(require 'deferred) -(require 'epc) -(autoload 'jedi:setup "jedi" nil t) -(add-hook 'python-mode-hook 'jedi:setup) -(setq jedi:setup-keys t) -;;/python-autocomplete;; - -;;php-mode;; -;; php-mode ------------------------------------------------------------------- -(autoload 'php-mode "php-mode" "PHP editing mode" t) -(add-to-list 'auto-mode-alist '("\\.php\\'" . php-mode)) -;;/php-mode;; - - -;;yasnippet;; -;; yasnippet configuration ---------------------------------------------------- -(require 'yasnippet) -(yas/initialize) -(yas/load-directory "~/.kuso.d/snippets") -;;/yasnippet;; - -;; flymake -------------------------------------------------------------------- -(require 'flymake) -(add-hook 'find-file-hook 'flymake-find-file-hook) - -;; pyflymake ------------------------------------------------------------------ -(when (load "flymake" t) - (defun flymake-pyflakes-init () - (let* ((temp-file (flymake-init-create-temp-buffer-copy - 'flymake-create-temp-inplace)) - (local-file (file-relative-name - temp-file - (file-name-directory buffer-file-name)))) - (list "--ADDR--/pyemacs.sh" (list local-file)))) - (add-to-list 'flymake-allowed-file-name-masks - '("\\.py$" flymake-pyflakes-init))) - -;; html flymake --------------------------------------------------------------- -(defun flymake-html-init () - (let* ((temp-file (flymake-init-create-temp-buffer-copy - 'flymake-create-temp-inplace)) - (local-file (file-relative-name - temp-file - (file-name-directory buffer-file-name)))) - (list "tidy" (list local-file)))) - -(add-to-list 'flymake-allowed-file-name-masks - '("\\.html$\\|\\.ctp" flymake-html-init)) - -(add-to-list 'flymake-err-line-patterns - '("line \\([0-9]+\\) column \\([0-9]+\\) - \\(Warning\\|Error\\): \\(.*\\)" - nil 1 2 4)) - -;; css flymake ----------------------------------------------------------------- -(defun flymake-css-init () - (let* ((temp-file (flymake-init-create-temp-buffer-copy - 'flymake-create-temp-inplace)) - (local-file (file-relative-name - temp-file - (file-name-directory buffer-file-name)))) - (list "cssparse" (list local-file)))) -(add-to-list 'flymake-allowed-file-name-masks - '("\\.css$" flymake-css-init)) -(add-to-list 'flymake-err-line-patterns - '("\\(.*\\) \\[\\([0-9]+\\):\\([0-9]+\\): \\(.*\\)\\]" - nil 2 3 1)) -(add-hook 'css-mode-hook - (lambda () (flymake-mode t))) - -;; flymake shortkeys -------------------------------------------------------------- -(global-set-key (kbd "\C-x a") 'flymake-display-err-menu-for-current-line) -(global-set-key (kbd "\C-x p") 'flymake-goto-next-error) - -;; JS folding -(add-hook 'js-mode-hook - (lambda () - ;; Scan the file for nested code blocks - (imenu-add-menubar-index) - ;; Activate the folding mode - (hs-minor-mode t))) - - -;;clang-mode;; -;; C configuration ---------------------------------------------------------------- -;; clang auto completion -(require 'auto-complete-clang) -(setq clang-completion-suppress-error 't) - -(defun my-c-mode-common-hook() - (setq ac-auto-start nil) - (setq ac-expand-on-auto-complete nil) - (setq ac-quick-help-delay 0.3) - (define-key c-mode-base-map (kbd "M-3") 'ac-complete-clang) -) - -;; Linux style for c programming ------------------------------------------------ -(setq c-default-style '((java-mode . "java") - (awk-mode . "awk") - (other . "linux"))) - -(add-hook 'c-mode-common-hook 'hs-minor-mode) -;;/clang-mode;; - -;; KUSO configuration ------------------------------------------------------------ -(load-file "--KUSOHOME--/src/kuso-ide.el") -(kuso-mode) - - -;;org-mode;; -;; org-mode ------------------------------------------------------ -(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode)) -(add-hook 'org-mode-hook 'turn-on-font-lock) ; not needed when(global-set-key "\C-cl" 'org-store-link) -(global-set-key "\C-ca" 'org-agenda) -(global-set-key "\C-cb" 'org-iswitchb) - -(add-hook 'before-save-hook 'delete-trailing-whitespace) -;;/org-mode;; - -;;cedet;; -;; Configuring ECB and CEDET -(load-file "~/.kuso.d/cedet/cedet-devel-load.el") -(add-to-list 'semantic-default-submodes 'global-semantic-idle-summary-mode t) -(add-to-list 'semantic-default-submodes 'global-semantic-idle-completions-mode t) - -(global-ede-mode 1) -(semantic-load-enable-code-helpers) -(global-srecode-minor-mode 1) -(add-to-list 'load-path "~/.kuso.d/ecb/") -(require 'ecb) -;;/cedet;; - -;;lua-mode;; -;; Lua mode -------------------- -(autoload 'lua-mode "lua-mode" "Lua editing mode." t) -(add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode)) -(add-to-list 'interpreter-mode-alist '("lua" . lua-mode)) -(add-hook 'lua-mode-hook 'hs-minor-mode) -;;/lua-mode;; - -;; JS folding ---------------- -(add-hook 'js-mode-hook - (lambda () - ;; Scan the file for nested code blocks - (imenu-add-menubar-index) - ;; Activate the folding mode - (hs-minor-mode t))) - - -;; Yaml mode -------------------------------------- -(require 'yaml-mode) -(add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode)) - -(add-hook 'yaml-mode-hook - '(lambda () - (define-key yaml-mode-map "\C-m" 'newline-and-indent))) - -;;git-gutter;; -;; git-gutter ------------------ -(require 'git-gutter) -(require 'git-gutter-fringe) - -(global-git-gutter-mode t) - -(add-hook 'ruby-mode-hook 'git-gutter-mode) -(add-hook 'python-mode-hook 'git-gutter-mode) - -(global-set-key (kbd "C-x C-g") 'git-gutter:toggle) - -(global-set-key (kbd "C-x p") 'git-gutter:previous-diff) -(global-set-key (kbd "C-x n") 'git-gutter:next-diff) -;;/git-gutter;; - -;; Yaml mode -------------------------------------- -(require 'yaml-mode) -(add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode)) - -(add-hook 'yaml-mode-hook - '(lambda () - (define-key yaml-mode-map "\C-m" 'newline-and-indent))) - - -(autoload 'inf-ruby "inf-ruby" "Run an inferior Ruby process" t) -(autoload 'inf-ruby-setup-keybindings "inf-ruby" "" t) -(eval-after-load 'ruby-mode - '(add-hook 'ruby-mode-hook 'inf-ruby-setup-keybindings)) - -(add-to-list 'load-path "~/.kuso.d/rinari") -(require 'rinari) - -(setq rinari-tags-file-name "TAGS") - - -(add-to-list 'load-path "~/.kuso.d/rhtml") -(require 'rhtml-mode) -(add-hook 'rhtml-mode-hook - (lambda () (rinari-launch))) - - - -(show-paren-mode t) - -(require 'haml-mode) -(require 'sass-mode) +(el-get 'sync kuso:el-get-packages) diff --git a/install.sh b/install.sh index ba9add0..27c9c07 100755 --- a/install.sh +++ b/install.sh @@ -1,32 +1,95 @@ #! /bin/bash -VERSION=$(emacs -l src/lib/version.el --eval "(princ (get_version))" --batch -Q) +# Kuso IDE installer script +# Its a very quick way to install Kuso IDE +# I now this code is not very nice but who cares it works + + +VERSION=1.0.0 + +remoteconffile="http://raw.github.com/Karajlug/KusoIDE/1.0/conf/dotkuso" +remoteexecutable="http://raw.github.com/Karajlug/KusoIDE/1.0/bin/kuso" + +conffile=conf/dotkuso + +mode="basic" + +REQUIREMENTS=(emacs git) + +# Coloring Functions +function info() { + echo -e "[\033[01;32mINFO\033[00m]: $1" +} + +function error(){ + echo -e "[\033[01;31mERR\033[00m]: $1" +} + +function warn(){ + echo -e "[\033[01;33mWARN\033[00m]: $1" +} + +function requirements_check(){ + for app in "${REQUIRMENTS[@]}" + do + info "Check for $app" + if hash $1 2>/dev/null; then + info "$app is present" + else + REQUIREMENTS_CHECK=false + error "Can not find $app" + fi + done +} + + + +while getopts ":e" option +do + case "${option}" + in + e)mode="expert";; + esac +done # Gathering informations -echo -e "\n\tKuso IDE $VERSION copyright 2010-2011 Sameer Rahmani \n\n" +echo -e "\n\033[01;32mKuso IDE\033[00m $VERSION copyright 2010-2013 \033[01;34mSameer Rahmani \033[00m\n\n" + +# Requirments check to make sure everything is ok +echo -e "Requirment Check" +# if this variable changed to fasle , means we have something to install +REQUIREMENTS_CHECK=true +requirements_check $REQUIREMENTS +# exit if our requirement check +if [ $REQUIREMENTS_CHECK == false ]; then + error "Please install requirments first"; + exit; +fi +echo -e "\n\n" + echo "Enter requested informations. You can change it later in top" -echo -e "level customization.\n\n" +echo -e "your init file.\n\n" + condition="1" while [ "$condition" == "1" ] ; do read -p "Do you want to install Kuso IDE as an stand alone application ([y]/n)? " standalone if [ "$standalone" == "" -o "$standalone" == "y" ] then - standalone="y" - dotemacs=~/.kuso - repo=~/.kuso.d - condition="0" - conffile=conf/dotkuso + standalone="y" + dotemacs=~/.kuso_dev + repo=~/.kuso.d_dev + condition="0" + executable=kuso fi if [ "$standalone" == "n" ] then - dotemacs=~/.emacs - repo=~/.emacs.d - condition="0" - conffile=conf/dotemacs + dotemacs=~/.emacs + repo=~/.emacs.d + condition="0" + executable=kuso fi - done read -p "Enter your full name: " fullname @@ -39,43 +102,48 @@ then workspace="$HOME/src/" fi -addr=$HOME/.kuso.d - # Installing stage1 -kusohome=`pwd` +info "Creating configuration folder in $repo" mkdir -p $repo + if [ -e $dotemacs ]; then - echo "Backing up exists .emacs file . . ." - cp $dotemacs "$dotemacs.backup" + info "An init file already exists." + info "Backing up exists init file to $dotemacs.backup . . ." + #cp $dotemacs "$dotemacs.backup" fi -echo "Copying files . . . " -cp conf/emacs.d/* $repo -r -mkdir -p $addr -mkdir -p $HOME/.tmp -cp conf/bin/pyemacs.sh $addr/ -r -chmod u+x $addr/pyemacs.sh -echo "Creating ~/.emacs" -cp $conffile $dotemacs - -if [ "$standalone" == "y" ] +if [ -e $conffile ] then - cp bin/kuso $repo - cp bin/kuso.desktop $HOME/.local/share/applications/ - sed "s,--HOME--,$HOME,mg" -i $HOME/.local/share/applications/kuso.desktop - cp images/icon.svg $repo + info "Copying init files . . . " + cp $conffile $dotemacs + cp bin/$executable $repo/$executable +else + info "Downloading init file and executable . . ." + wget $remoteconffile -q -O $dotemacs + wget $remoteexecutable -q -O $repo/$executable +fi + +if [ "$standalone" == "" -o "$standalone" == "y" ] +then + info "Creating a link in globe PATH . . ." + sudo ln -s $repo/$executable /usr/bin/$executable-dev + chmod +x $repo/$executable fi sed "s/--EMAIL--/$mail/mg" -i $dotemacs sed "s/--FULLNAME--/$fullname/mg" -i $dotemacs sed "s,--WORKSPACE--,$workspace,mg" -i $dotemacs -sed "s,--ADDR--,$addr,mg" -i $dotemacs -sed "s,--KUSOHOME--,$kusohome,mg" -i $dotemacs +sed "s,--REPO--,$repo,mg" -i $dotemacs -echo "Copy the below code in your initial shell script:" -echo -echo "export PATH=\$PATH:$repo" -echo -e "\nInstallation finished." -echo "Restart the GNU/Emacs and make sure that all the requirements met." -echo -printf "\033[01;33mImportant Note:\033[00m Do NOT remove the Kuso IDE source.\n" + +#if [ $mode == "expert" ] +#then +# info "Installing base system . . ." +# echo "(setq KUSO-INSTALL-MODE \"expert\")" > /tmp/init_kuso_installer.el +# `which emacs` --batch -l /tmp/init_kuso_installer.el -l $dotemacs +#else +# info "Installing base system . . ." +# `which emacs` --batch -l $dotemacs +#fi + +echo -e "\nNow run 'kuso' and have fun ;)" diff --git a/src/lib/about.el b/src/lib/about.el deleted file mode 100644 index ce55eb9..0000000 --- a/src/lib/about.el +++ /dev/null @@ -1,51 +0,0 @@ -;; Kuso - My personal emacs IDE -;; Copyright (C) 2010-2011 Sameer Rahmani -;; -;; This program is free software: you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; any later version. -;; -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. -;; -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -(defvar aboutkusoidemsg " -Kuso IDE %%VERSION%% Copyright © 2010-2011 Sameer Rahmani -Kuso IDE release under the term of GPLv2. - -Home page: -\thttp://kuso.lxsameer.com - -Credits: -\tSameer Rahmani (lxsameer) -\tBehnam Ahmad Khan Beigi (b3hnam) -\tNima Nazari (niman) - -" - "About Kuso IDE") - - - -(defun about/get_string () - "Get the about message string" - (let (msg) - (setq msg (replace-regexp-in-string "%%VERSION%%" KUSO-VERSION aboutkusoidemsg)) - ) -) - -(defun about-kuso-f () - "Show an small about note" - (interactive) - (let (buf msg) - (setq buf (get-buffer-create "*About Kuso IDE*")) - (setq msg (about/get_string)) - (set-buffer buf) - (insert msg) - (view-buffer buf) - ) -) diff --git a/src/plugins/dpaste.el b/src/plugins/dpaste.el deleted file mode 100644 index ab4f6e4..0000000 --- a/src/plugins/dpaste.el +++ /dev/null @@ -1,214 +0,0 @@ -;; Kuso - My personal emacs IDE -;; Copyright (C) 2010 Sameer Rahmani -;; -;; This program is free software: you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation, either version 3 of the License, or -;; any later version. -;; -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. -;; -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;; dpaste.com plugin - -;; ------------------------------------------------------------------- -;; Variables -;; ------------------------------------------------------------------- - -;; This variable copied from an other dpaste.el at -;; https://github.com/gregnewman/dpaste.el/blob/master/dpaste.el -(defvar dpaste-support-types '((css-mode . "Css") - (diff-mode . "Diff") - (haskell-mode . "Haskell") - (html-mode . "DjangoTemplate") - (javascript-mode . "JScript") - (js2-mode . "JScript") - (python-mode . "Python") - (inferior-python-mode . "PythonConsole") - (ruby-mode . "Ruby") - (sql-mode . "Sql") - (sh-mode . "Bash") - (xml-mode . "Xml"))) -;; ------------------------------------------------------------------- -;; Hooks -;; ------------------------------------------------------------------- -(defvar kuso-dpaste-preinit-hook '() - "This hook runs before initializing the Kuso dpaste-plugin minor mode." - ) - -(defvar kuso-dpaste-postinit-hook '() - "This hook runs after Kuso dpaste-plugin minor mode initialized." - ) - -(defvar kuso-dpaste-prerm--hook '() - "This hook runs before deactivating Kuso dpaste-plugin minor mode." - ) - -(defvar kuso-dpaste-postrm-hook '() - "This hook runs after Kuso dpaste-plugin minor mode deactivated." - ) - -;; --------------------------------------------------------------------- -;; Keymaps -;; --------------------------------------------------------------------- -(defvar kuso-dpaste-map (make-sparse-keymap) - "Default keymap for Kuso dpaste minor mode that hold the global key -binding for Kuso IDE dpaste plugin" -) - -;; --------------------------------------------------------------------- -;; Custom Variables -;; --------------------------------------------------------------------- -(defcustom dpaste-plugin t - "KusoIDE dpaste plugin." - :group 'kuso-features - :type 'boolean - :tag '"dpaste.com plugins") - -;; ---------------------------------------------------------------------- -;; Functions -;; ---------------------------------------------------------------------- -(defun init-keymap () - "Initialize the keymap for dpaste plugin." - (define-key kuso-dpaste-map (kbd "\C-x p d") 'dpaste-region) - (define-key kuso-dpaste-map (kbd "\C-x p f") 'dpaste-buffer) - ) - -(defun init-menus () - "Initialize menu entry for dpaste plugin." - (define-key-after global-map [menu-bar edit sep1] '("--") 'paste-from-menu) - (define-key-after global-map [menu-bar edit dpastereg] '("Dpaste Selected" . dpaste-region) 'sep1) - (define-key-after global-map [menu-bar edit dpastebuf] '("Dpaste Buffer" . dpaste-buffer) 'dpastereg) - - (define-key-after global-map [menu-bar edit sep2] '("--") 'dpastebuf) - ) - -(defun destruct-menus () - "Remove menus from menubar" - (global-unset-key [menu-bar edit sep1]) - (global-unset-key [menu-bar edit sep2]) - (global-unset-key [menu-bar edit dpastereg]) - (global-unset-key [menu-bar edit dpastebuf]) - ) - -(defun get-region-text () - "Retrive the region (selected) text." - (let (text start end tmp) - (setq start (region-beginning)) - (setq end (region-end)) - (if (> start end) - (progn - (setq tmp start) - (setq start end) - (setq end tmp) - ) - ) - (setq text (buffer-substring-no-properties start end)) - ) -) - - -(defun dpaste-region () - "dpaste the region and return the URL." - (interactive) - (let (a b text type title poster) - (setq text (get-region-text)) - - - (setq title (or (buffer-file-name) (buffer-name))) - ;; TODO: poster should be the name of current developer - (setq poster "sameer") - (setq type (or (cdr (assoc major-mode dpaste-support-types)) "")) - (with-temp-buffer - (insert text) - (shell-command-on-region (point-min) (point-max) (concat "curl -si" " -F 'content=<-'" - " -A 'Kuso dpaste plugin'" - " -F 'language=" type "'" - " -F 'title=" title "'" - " -F 'poster=" poster "'" - " http://dpaste.com/api/v1/") (buffer-name)) - - - - (goto-char (point-min)) - (setq a (search-forward-regexp "^Location: ")) - (setq b (search-forward-regexp "http://dpaste.com/[0-9]+/")) - (message "Link: %s" (buffer-substring a b)) - (kill-new (buffer-substring a b)) - ) - ) - ) - - -(defun dpaste-buffer () - "dpaste the current-buffer content." - (interactive) - (let (a b text type title poster) - - (setq title (or (buffer-file-name) (buffer-name))) - ;; TODO: poster should be the name of current developer - (setq poster "sameer") - (setq type (or (cdr (assoc major-mode dpaste-support-types)) "")) - (setq text (buffer-string)) - (with-temp-buffer - (insert text) - (shell-command-on-region (point-min) (point-max) (concat "curl -si" " -F 'content=<-'" - " -A 'Kuso dpaste plugin'" - " -F 'language=" type "'" - " -F 'title=" title "'" - " -F 'poster=" poster "'" - " http://dpaste.com/api/v1/") (buffer-name)) - - (goto-char (point-min)) - (setq a (search-forward-regexp "^Location: ")) - (setq b (search-forward-regexp "http://dpaste.com/[0-9]+/")) - (message "Link: %s" (buffer-substring a b)) - (kill-new (buffer-substring a b)) - ) - ) -) - -;; ---------------------------------------------------------------------- -;; Minor Modes -;; ---------------------------------------------------------------------- -(define-minor-mode kuso-dpaste-mode - "Toggle Kuso dpaste plugin mode. -This mode provide an easy way to dpaste a buffer or a snippet of text in -http://www.dpaste.com/ - -By marking a region and C-x p d this plugin dpaste the code and put the url -in killring and also message the url. You can also use C-x p f to dpaste -the current buffer." - :lighter nil - :keymap kuso-dpaste-map - :global t - :group 'kuso-group - - (if kuso-dpaste-mode - ;; kuso-cplugin-mode is not loaded - (let () - ;; before initiazing mode - (run-hooks 'kuso-dpaste-preinit-hook) - (init-keymap) - (init-menus) - (put 'dpaste-region 'menu-enable nil) - (force-mode-line-update) - ;; after mode was initialized - (run-hooks 'kuso-dpaste-postinit-hook) - ) - ;; kuso-mode already loaded - (let () - ;; before deactivating mode - (run-hooks 'kuso-dpaste-prerm-hook) - (destruct-menus) - ;; after deactivating mode - (run-hooks 'kuso-dpaste-postrm-hook) - ) - ) - ) -(provide 'dpaste) \ No newline at end of file