Merge lp:~lielft-deactivatedaccount/rtlplo0x/first-char-bugfix into lp:rtlplo0x

Proposed by Liel Fridman
Status: Merged
Merged at revision: 2
Proposed branch: lp:~lielft-deactivatedaccount/rtlplo0x/first-char-bugfix
Merge into: lp:rtlplo0x
Diff against target: 86 lines (+75/-0) (has conflicts)
1 file modified
RTLplo0x.py (+75/-0)
Text conflict in RTLplo0x.py
To merge this branch: bzr merge lp:~lielft-deactivatedaccount/rtlplo0x/first-char-bugfix
Reviewer Review Type Date Requested Status
Ddorda Approve
Review via email: mp+42772@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ddorda (ddorda) wrote :

This is a patch and not a standing commit. please publish a full code for merge or upload the patch to the right bug report. Thanks!

review: Needs Fixing
Revision history for this message
Ddorda (ddorda) wrote :

My bad. works excellent! stupid LP.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'RTLplo0x.py'
--- RTLplo0x.py 2010-12-05 10:04:40 +0000
+++ RTLplo0x.py 2010-12-05 10:14:52 +0000
@@ -1,3 +1,4 @@
1<<<<<<< TREE
1#!/usr/bin/python2#!/usr/bin/python
2# -*- coding: utf-8 -*-3# -*- coding: utf-8 -*-
3"""4"""
@@ -70,3 +71,77 @@
70 return xchat.EAT_XCHAT # disable regular Xchat function71 return xchat.EAT_XCHAT # disable regular Xchat function
7172
72xchat.hook_command("", check_chars)73xchat.hook_command("", check_chars)
74=======
75#!/usr/bin/python
76# -*- coding: utf-8 -*-
77"""
78 Wrote by: Ddorda <Ddorda Strüdle(at) ubuntu.com> - <http://ddorda.useopensource.net> and cleaned by MKsoft
79
80 This program (As known as "RTLplo0x") is free software: you can redistribute it and/or modify
81 it under the terms of the GNU General Public License as published by
82 the Free Software Foundation, either version 3 of the License, or
83 (at your option) any later version.
84
85 This program is distributed in the hope that it will be useful,
86 but WITHOUT ANY WARRANTY; without even the implied warranty of
87 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88 GNU General Public License for more details.
89
90 You should have received a copy of the GNU General Public License
91 along with this program. If not, see <http://www.gnu.org/licenses/>.
92
93
94 -------------------------
95
96README:
97 - This is an Xchat2 plugin. to install it you should copy this file into ~/.xchat2/ directory.
98 - RTLplo0x supports any known RTL/LTR language, even though it was written for Hebrew/English in the beggining.
99"""
100
101import xchat
102from unicodedata import lookup, bidirectional
103
104__module_name__ = "RTLplo0x"
105__module_version__ = "1.0"
106__module_description__ = "RTL my /MSG Plo0x!"
107
108# some constants for readability
109RLM = lookup('RIGHT-TO-LEFT MARK')
110LRM = lookup('LEFT-TO-RIGHT MARK')
111
112# we take into account 'L' as strong left, and 'R' and 'AL' as strong
113# right. If you want other types, add them here. For more info see:
114# http://unicode.org/reports/tr9/#Bidirectional_Character_Types
115STRONG_LEFT = ('L', )
116STRONG_RIGHT = ('R', 'AL')
117
118def check_chars(word, word_eol, userdata):
119 """Count the strong right and left bidirectional char types. Based on the
120 Unicode algorithm. Ignores if it starts with RLM or LRM (allowing to
121 override behavior). Assumes that text is utf-8 encoded
122
123
124 """
125
126 unistr = word_eol[0].decode('utf-8')
127 if not unistr.startswith( (RLM, LRM, '!', '@', '+', '-', '.') ):
128 # holds the count of char types. Key is char type, value is count
129 char_types = {}
130 for unichar in unistr:
131 char_type = bidirectional(unichar)
132 char_types[char_type] = char_types.get(char_type, 0) + 1
133
134 total_left = sum( char_types.get(x, 0) for x in STRONG_LEFT )
135 total_right = sum( char_types.get(x, 0) for x in STRONG_RIGHT )
136
137 if len(word) > 0 and word[0].endswith( ":" ): total_left = ( total_left - len( word[0] ) + 1 ) # total_left = itself without "nick:"
138
139 if total_right > total_left:
140 unistr = RLM + unistr
141 else:
142 unistr = LRM + unistr
143 xchat.command("say " + unistr.encode('utf-8')) # print fixed text
144 return xchat.EAT_XCHAT # disable regular Xchat function
145
146xchat.hook_command("", check_chars)
147>>>>>>> MERGE-SOURCE

Subscribers

People subscribed via source and target branches

to all changes: